gtpc2m5kC/C++ Language Support User's Guide

raise-Raise Condition

This function sends the signal sig to the program that called the raise function.

Use the sigaction function or the signal function to specify how a signal is handled when the raise function is called.

Default processing for signals when the signal handler is SIG_DFL is in internal library function __sigdfp. See Table 13 for SIG_DFL handler action for the signals. The SIG_DFL handler actions can be changed by modifying __sigdfp code in CSIGDP.

Format

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

sig
The signal sent to the program that issued the raise function.

See Table 13 for the list of supported signals.

Normal Return

The returned value is 0.

Error Return

A nonzero error return indicates that the function was not successful.

Programming Considerations

Examples

This example establishes a signal handler called sig_hand for the signal SIGUSR1. The signal handler is called whenever the SIGUSR1 signal is raised; it ignores the first 9 occurrences of the signal. On the tenth raised signal, it prints a message and returns without establishing the signal handler again. Note that the signal handler must be established again each time it is called.

Note:
The signal handler must be established each time the raise function is called because the signal handler is installed by the signal function.
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
void sig_hand(int);   /* declaration of sig_hand() as a function */
int i;
void ADLM(void)
{
   signal(SIGUSR1, sig_hand);  /* set up handler for SIGUSR1 */
   for (i=0; i<10; ++i)
      raise(SIGUSR1);             /* signal SIGUSR1 is raised */
}                            /* sig_hand() is called */
 void sig_hand(int);
   static int count = 0;          /* initialized only once */
   count++;
   if (count == 10) { /* ignore the first 9 occurrences of this signal */
      printf("reached 10th signal\n");
      return;
   }
   else
      signal(SIGUSR1, sig_hand);  /* set up the handler again */
}

Related Information