### raise -- Send Signal

Format

>     #include <signal.h>
>     int raise(int sig);

Language Level: ANSI, XPG4
raise sends the signal sig to the running program. You can then use signal to handle sig.

Return Value
raise returns 0 if successful, nonzero if unsuccessful.

Example
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>
    #include <stdlib.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 (count == 10)  /* ignore the first 9 occurrences of this signal */
          exit(10);
       else
          signal(SIGUSR1, sig_hand);  /* set up the handler again */
          raise(SIGUSR1);
    }

Handling Signals and Exceptions

signal -- Handle Interrupt Signals
<signal.h>