2011年11月15日 星期二

[Unix Programming] Zombie

Zombie: Child process terminates without parent's waiting.
As a result, all you have to do is to wait the child process while terminating.


void waitchild() {
  signal( SIGCHLD, waitchild); // re-enable the signal to fit all systems
  while( wait(NULL) <= 0 )
    /*NOTHING*/;
}


int
main (int argc, char **argv)
{
  signal( SIGCHLD, waitchild);
  if (fork() == 0) {
    // child process
  } else {
    // parent
  }
}

Refer:
http://home.educities.edu.tw/shirock/comp/Anti_zombie_process.htm
http://starryalley.twbbs.org/blog/index.php?/archives/683-linux-zombie-process.html

沒有留言:

張貼留言