/*
 * Signal test; 
 * tests killing of processes from the command line
 */

#include <signal.h>
#include <stdio.h>
#include <errno.h>


#define SIGNAL SIGUSR1         
#define SIGNAL SIGINT         
     
static int handler( int signr )
{
    printf(" IN HANDLER, signr=%d\n", signr );  
}

#define D(x) if (x) { printf("System call failure : " #x " errno=%d\n", errno); }


main() {
    
    struct sigaction act;
    sigset_t  sigset;
    int       pid;

    act.sa_handler= handler;
    act.sa_flags  = 0;
    sigemptyset(&act.sa_mask);

    D( sigaction( SIGNAL, &act, 0) );

    pid= fork();

    if (pid) {
           printf(" CHILD= %d; kill it with signal %d!\n",pid,SIGNAL);   
           printf(" PARENT TERMINATED\n");   
    } else {
           D( sigsuspend(&sigset) );
           printf(" CHILD TERMINATED\n");   
    }
         
}
