How to solve Zombie and Orphan Process Problems ?

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

    How to solve Zombie and Orphan Process Problems ?

    Hey guys i need help on this problem ..
    How to solve zombie and orphan process problems ?
    Please explain with an example...
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    Originally posted by alikhan707
    Hey guys i need help on this problem ..
    How to solve zombie and orphan process problems ?
    Please explain with an example...

    when you fork a new process, it's parents responsibility to query the exit status of the child. This exit status can be queried by system calls like 'wait','waitpid ' etc
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/wait.h>
    main()
    {
      int i, j, status;
      i = fork();
      if (i > 0) //parent 
      {
        j = wait(&status);
      } 
      else //child
      {
           sleep(1000);
            exit(0);
      }
    }
    In this code parent will wait till child finishes.
    So in short..parent must issue a wait call to avoid a zombie processes.

    Comment

    • alikhan707
      New Member
      • Mar 2008
      • 4

      #3
      Thanks it works ............

      Comment

      Working...