Reputation: 131
I am reading an article about signal and there was this part of the code which I am not sure what it is doing. Could somebody explain it for me? This article is about creating TCP un-blocked server.
struct sigaction sigchldAction;
sigchldAction.sa_handler = SIG_IGN;
sigchldAction.sa_flags = 0;
sigemptyset(&sigchldAction.sa_mask);
if (sigaction(SIGCHLD, &sigchldAction, NULL) == -1) callError("sigaction()");
Upvotes: 0
Views: 844
Reputation: 119034
According to the Linux manual page for sigaction
:
POSIX.1-1990 disallowed setting the action for SIGCHLD to SIG_IGN. POSIX.1-2001 allows this possibility, so that ignoring SIGCHLD can be used to prevent the creation of zombies (see wait(2)).
That is, explicitly ignoring SIGCHLD
using SIG_IGN
has the effect of causing the OS to automatically destroy child processes upon termination, so that you don't have to wait*
for them. This is often what you want, although sometimes it isn't, because it also prevents the parent process from using wait*
to determine the child's exit status.
Upvotes: 2