../common/catchchildren.c
///////////////////////////////////////////////////////////////////////////////
// Filename: catchchildren.c
///////////////////////////////////////////////////////////////////////////////
// Purpose: install a signal handler that cares about zombies generated by fork
///////////////////////////////////////////////////////////////////////////////
// History:
// ========
//
// Date Time Name Description
// -------- -------- -------- ------------------------------------------------
// 96/02/29 13:42:12 muellerg: created
//
///////////////////////////////////////////////////////////////////////////////
// Feature test switches ///////////////////////////// Feature test switches //
/* NONE */
// System headers /////////////////////////////////////////// System headers //
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
// Local headers ///////////////////////////////////////////// Local headers //
#include "../common.h"
// Macros /////////////////////////////////////////////////////////// Macros //
/* NONE */
// File scope objects /////////////////////////////////// File scope objects //
/* NONE */
// External variables, functions, and classes ///////////// External objects //
/* NONE */
// Signal catching functions ///////////////////// Signal catching functions //
static void
sig_child(int) /* signal handler for SIGCHLD */
{
waitpid(WAIT_ANY, NULL, WNOHANG);
return;
}
// Structures, unions, and class definitions /////////////////// Definitions //
/* NONE */
// Functions and class implementation /// Functions and class implementation //
void catch_children(void)
{
struct sigaction handle_sigchild;
handle_sigchild.sa_handler = &sig_child;
sigemptyset(&handle_sigchild.sa_mask); // no need to block other signals
#ifdef SA_RESTART
handle_sigchild.sa_flags = SA_RESTART; // restart interrupted
// system calls automatically
#else
handle_sigchild.sa_flags = 0; // HP-UX 9.01 does not support this
// option
#endif
if(sigaction(SIGCHLD, &handle_sigchild, NULL) != 0)
error.system("catch_children(): sigaction error");
}
// Main /////////////////////////////////////////////////////////////// Main //
/* NONE */