raise() — Send Signal
Format
#include <signal.h>
int raise(int sig);
Language Level
ANSI
Threadsafe
Yes
Description
The raise()
function
sends the signal sig to the running program.
If compiled with SYSIFCOPT(*ASYNCSIGNAL) on the compilation command,
this function uses asynchronous signals. The asynchronous version
of this function throws a signal to the process or thread.
Return Value
The raise()
function
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>
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 */
}
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 */
}
/* This is a program fragment and not a complete program */
Related Information
- signal() — Handle Interrupt Signals
- Signal Handling Action Definitions
- <signal.h>
- Signal APIs in the APIs topic in the Information Center.
- POSIX thread APIs in the APIs topic in the Information Center.