Linux: prevent zombie state for child processes

Setting the handler for SIGCHLD to SIG_IGN (ignore) informs the kernel
not to enter the zombie state: (man 2 wait)

  POSIX.1-2001 specifies that if the disposition of SIGCHLD is set to
  SIG_IGN or the SA_NOCLDWAIT flag is set for SIGCHLD (see
  sigaction(2)), then children that terminate do not become zombies
  [...]

Fixes #271.
This commit is contained in:
Christian Helmuth 2012-07-09 17:51:39 +02:00
parent af51aa1c0f
commit f730a9c343
4 changed files with 16 additions and 0 deletions

View File

@ -40,6 +40,11 @@ static void thread_start(void *)
*/
lx_sigaction(LX_SIGUSR1, empty_signal_handler);
/*
* Prevent children from becoming zombies. (SIG_IGN = 1)
*/
lx_sigaction(LX_SIGCHLD, (void (*)(int))1);
Thread_base::myself()->entry();
sleep_forever();
}

View File

@ -32,6 +32,11 @@ static void thread_start(void *)
*/
lx_sigaction(LX_SIGUSR1, empty_signal_handler);
/*
* Prevent children from becoming zombies. (SIG_IGN = 1)
*/
lx_sigaction(LX_SIGCHLD, (void (*)(int))1);
Thread_base::myself()->entry();
sleep_forever();
}

View File

@ -314,6 +314,7 @@ inline int lx_stat(const char *path, struct stat64 *buf)
enum {
LX_SIGUSR1 = 10, /* used for cancel-blocking mechanism */
LX_SIGCHLD = 17, /* child process changed state, i.e., terminated */
LX_SIGCANCEL = 32, /* accoring to glibc, this equals SIGRTMIN,
used for killing threads */
};

View File

@ -167,6 +167,11 @@ static void adopt_thread(Thread_meta_data *meta_data)
*/
lx_sigaction(LX_SIGUSR1, empty_signal_handler);
/*
* Prevent children from becoming zombies. (SIG_IGN = 1)
*/
lx_sigaction(LX_SIGCHLD, (void (*)(int))1);
/* assign 'Thread_meta_data' pointer to TLS entry */
pthread_setspecific(tls_key(), meta_data);