sigaction
Prototype:
#include <signal.h>
int sigaction(int signum, const struct sigaction *sigact,
        struct sigaction *oldsigact);
General Description: Similar to signal(), sigaction() establishes the receiver of certain signals. Unlike signal, however, this call gives you a lot more control over how the signaling notification behaves. It is also a little more complicated to use.
Return Value: Zero upon success; nonzero, otherwise.
Parameters
signum The signal to capture.
sigact The desired behavior and signal handler, using this structure:struct sigaction{void (*sa_handler)(int);sigset_t sa_mask;int sa_flags;void (*sa_restorer)(void);};sa_handler - signal handler function pointer.sa_mask - the set of signals to block while servicing a signal in the signal handler.sa_restorer - (obsolete -- do not use)sa_flags - how to handle the signals. You can use these flags:SA_NOCLDSTOP - If the signal is SIGCHLD, ignore cases when the child stops or pauses.SA_ONESHOT or SA_RESETHAND - Reset the handler to the default after getting the first signal.SA_RESTART - Try to restart an interrupted system call. Normally, system calls that are interrupted return an EINTR error. This option tries to restart the call and avoid EINTR errors.SA_NOMASK or SA_NODEFER - Allow like signals to interrupt the handler. Normally, if your handler is responding to a particular signal like SIGCHLD, the kernel suspends other SIGCHLD signals. This can lead to lost signals. Using this option permits your handler to be interrupted. Be careful using this option!
oldsigact A repository of the old behaviors. You may copy the old settings here.
Possible Errors
EINVAL An invalid signal was specified. This will also be generated if an attempt is made to change the action for SIGKILL or SIGSTOP, which cannot be caught.
EFAULT The sigact or oldsigact parameters point to memory which is not a valid part of the process address space.
EINTR System call was interrupted.
Examples
void sig_handler(int signum)
{
    switch ( signum )
    {
        case SIGCHLD:
...
    }
}

...
struct sigaction sigact;
bzero(&sigact, sizeof(sigact));
sigact.sa_handler = sig_handler;  /* set the handler */
sigact.sa_flags = SA_NOCLDSTOP | SA_RESTART; /* set options */
if ( sigaction(SIGCHLD, &sigact, 0) == 0 )
    perror("sigaction() failed");