Syntax
#include <signal.h> int raise(int sig);Description
raise sends the signal sig to the running program. You can then use signal to handle sig.
Signals and signal handling are described in signal, and in the VisualAge C++ Programming Guide under "Signal and Exception Handling".
raise returns 0 if successful, nonzero if unsuccessful.
This example establishes a signal handler called sig_hand for the signal SIGUSR1. The signal handler is called whenever the SIGUSR1 signal is raised and will ignore the first nine occurrences of the signal. On the tenth raised signal, it exits the program with an error code of 10. Note that the signal handler must be reestablished each time it is called.
#include <signal.h> #include <stdio.h> void sig_hand(int); /* declaration of sig_hand() as a function */ int main(void) { signal(SIGUSR1, sig_hand); /* set up handler for SIGUSR1 */ raise(SIGUSR1); /* signal SIGUSR1 is raised */ /* sig_hand() is called */ return 0; } void sig_hand(int sig) { static int count = 0; /* initialized only once */ count++; if (10 == count) /* ignore the first 9 occurrences of this signal */ exit(10); else signal(SIGUSR1, sig_hand); /* set up the handler again */ raise(SIGUSR1); }Related Information