By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,730 Members | 1,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,730 IT Pros & Developers. It's quick & easy.

How to solve Zombie and Orphan Process Problems ?

P: 4
Hey guys i need help on this problem ..
How to solve zombie and orphan process problems ?
Please explain with an example...
Mar 23 '08 #1
Share this Question
Share on Google+
2 Replies

ashitpro
Expert 100+
P: 542
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
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/wait.h>
  4. main()
  5. {
  6.   int i, j, status;
  7.   i = fork();
  8.   if (i > 0) //parent 
  9.   {
  10.     j = wait(&status);
  11.   } 
  12.   else //child
  13.   {
  14.        sleep(1000);
  15.         exit(0);
  16.   }
  17. }
  18.  
In this code parent will wait till child finishes.
So in short..parent must issue a wait call to avoid a zombie processes.
Mar 23 '08 #2

P: 4
Thanks it works ............
Mar 24 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.