/* * Sample program for signal system call - No.48 * * signal - ANSI C signal handling * * Synopsis * #include * * typedef void (*singhandler_t)(int); * * signalhandler_t signal(int signum, sighandler_t handlerj); * * Description * The signal () system call installs a new signal handler for * the signal with number signum. The signal handler is set to * sighandler which may be a user specified function, or either * SIG_IGN or SIG_DFL. * * Upon arrival of a signal with number signum the following * happens. If the corresponding handler is set to SIG_IGN, * then the signal is ignored. If the handler is set to SIG_DFL, * then the default action asscociated to the signal (see signal(7)) * occurs. Finally, if the handler is reset to SIG_DFL or an * implementation-dependant blocking of the signal is performed * and next sighandler is called wwith argument signum. * * Using a signal handler function for a signal is called * "catching the signal". The signals SIGKILL and SIGSTOP * cannot be caught or ignored. */ #include #define SIGUSER 60 void sig_user() { printf("user defined signal handler is evoked.\n"); } main() { int pid; signal(SIGUSER, sig_user); pid = getpid(); kill(pid, SIGUSER); exit(0); }