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

How to create Zombie ?

P: 4
Hey guys i need help on this problem ....
Please tell me how to create zombie in linux using fork() ?
Mar 21 '08 #1
Share this Question
Share on Google+
6 Replies

ashitpro
Expert 100+
P: 542
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.
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.      int pid;
  4.      pid=fork();
  5.      if(pid>0)//child
  6.      {
  7.            sleep(1000);
  8.      }
  9.      else//parent
  10.      { 
  11.            exit(0);
  12.      }
  13. }
  14.  
Mar 21 '08 #2

micmast
100+
P: 144
Couldn't the above code be shorter?

like this:

Expand|Select|Wrap|Line Numbers
  1. int main() {
  2. for(;;) {
  3. fork();
  4. }
  5. }
  6.  
Mar 21 '08 #3

P: 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...
Mar 22 '08 #4

P: 1
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.
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.      int pid;
  4.      pid=fork();
  5.      if(pid>0)//child
  6.      {
  7.            sleep(1000);
  8.      }
  9.      else//parent
  10.      { 
  11.            exit(0);
  12.      }
  13. }
  14.  
I have a doubt is not zombie and orphan two different process? how do you link these both? Please explain me
Aug 22 '08 #5

ashitpro
Expert 100+
P: 542
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...

http://wiki.answers.com/Q/What_is_Zo...Orphan_Process
Aug 27 '08 #6

Subsciber123
P: 87
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).
Sep 7 '08 #7

Post your reply

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