Listing 3. Explicitly Reaping the (dead) Child Process

/*
 * Listing 3:
 * Explicitly reaping the child:
 * Ivan Griffin (ivan.griffin@ul.ie)
 */
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
void ReapChild(int pid);
struct sigaction reapAction =
{
    ReapChild,      /* SIG_DFL for default,
                     * SIG_IGN to ignore,
                     * else handler */
    0,              /* mask of signals to block
                     * during handler execution */
    SA_RESTART,     /* don't reset to default
                     * is raised */
    NULL            /* Not used-should be NULL */
};
int main(int argc, char *argv[])
{
    /*
     * somewhere in main code
     */
    sigaction(SIGCHLD, &reapAction, NULL);
    /*
     * rest of code
     */
    return 0;
}
void ReapChild(int pid)
{
    int status;
    wait(&status);
}