How to create Zombie ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alikhan707
    New Member
    • Mar 2008
    • 4

    How to create Zombie ?

    Hey guys i need help on this problem ....
    Please tell me how to create zombie in linux using fork() ?
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    Originally posted by alikhan707
    Hey guys i need help on this problem ....
    Please tell me how to create zombie in linux using fork() ?
    when parent process issues a fork system call, it spawns a child process.
    Idly parent should query the exit status of the child process by system calls like waitpid,wait etc.
    But if parent process fails to do this or never issues such calls and just get terminate, then child process is said to be zombie(other name is orphan) i.e process having no parent. It just exists in memory holding the resources.
    Code:
    int main()
    {
         int pid;
         pid=fork();
         if(pid>0)//child
         {
               sleep(1000);
         }
         else//parent
         { 
               exit(0);
         }
    }

    Comment

    • micmast
      New Member
      • Mar 2008
      • 144

      #3
      Couldn't the above code be shorter?

      like this:

      Code:
      int main() {
      for(;;) {
      fork();
      }
      }

      Comment

      • alikhan707
        New Member
        • Mar 2008
        • 4

        #4
        Hey guys thanx for the replies :)
        Next question, i want to ask is that how to solve these both zombie and orphan process problems ? Can u explain with an example ?
        thanx...

        Comment

        • jrichard
          New Member
          • Aug 2008
          • 1

          #5
          Originally posted by ashitpro
          when parent process issues a fork system call, it spawns a child process.
          Idly parent should query the exit status of the child process by system calls like waitpid,wait etc.
          But if parent process fails to do this or never issues such calls and just get terminate, then child process is said to be zombie(other name is orphan) i.e process having no parent. It just exists in memory holding the resources.
          Code:
          int main()
          {
               int pid;
               pid=fork();
               if(pid>0)//child
               {
                     sleep(1000);
               }
               else//parent
               { 
                     exit(0);
               }
          }
          I have a doubt is not zombie and orphan two different process? how do you link these both? Please explain me

          Comment

          • ashitpro
            Recognized Expert Contributor
            • Aug 2007
            • 542

            #6
            Originally posted by jrichard
            I have a doubt is not zombie and orphan two different process? how do you link these both? Please explain me
            Go through this link...
            If you still have any doubts let us know...

            Zombie : Child Process Exits before Parent process and Parent does not grab status of child process using wait() or waitpid() system call; Child process is in Zombie state. Orphan : Child process whose parent has been killed and inherited by init process.

            Comment

            • Subsciber123
              New Member
              • Nov 2006
              • 87

              #7
              Zombies are processes that have terminated but whose return value has not been read by the parent. waitpid() collects return values and kills zombies.

              Orphans are child processes whose parents have died. Orphans are supposed to be adopted by init (which has PID=1).

              Comment

              Working...