C examples for signal.h:raise
function
<csignal>
Generates a signal which is handled as specified by function signal.
int raise (int sig);
Parameter | Description |
---|---|
sig | The signal value to raise. |
The following macro constant expressions identify standard signal values:
macro | stands for | signal |
---|---|---|
SIGABRT | Signal Abort | Abnormal termination. |
SIGFPE | Signal Floating-Point Exception | Erroneous arithmetic operation. |
SIGILL | Signal Illegal Instruction | due to a corruption in the code or to an attempt to execute data. |
SIGINT | Signal Interrupt | Generally generated by the application user. |
SIGSEGV | Signal Segmentation Violation | Invalid access to storage when trying to access outside the memory it is allocated for it. |
SIGTERM | Signal Terminate | Termination request sent to program. |
On success, returns zero.
On error, a value different from zero otherwise.
#include <stdio.h> #include <signal.h> sig_atomic_t signaled = 0;//from ww w . j av a 2 s . c om void my_handler (int param){ signaled = 1; } int main (){ void (*prev_handler)(int); prev_handler = signal (SIGINT, my_handler); raise(SIGINT); printf ("signaled is %d.\n",signaled); return 0; }