C++ <csignal> - raise() Function
The C++ <csignal> raise() function sends signal sig to the current executing program. The signal handler, specified using signal(), is invoked.
If the user-defined signal handling strategy is not set using signal() yet, it is implementation-defined whether the signal will be ignored or default handler will be invoked.
Syntax
int raise (int sig);
Parameters
sig |
Specify the signal to be sent. It can be an implementation-defined value or one of the following values:
|
Return Value
Returns zero upon success, non-zero value on failure.
Example:
The example below shows the usage of raise() function.
#include <csignal> #include <cstdio> volatile sig_atomic_t gSignalStatus = 0; void signal_handler(int signal) { gSignalStatus = signal; } int main(void) { //installing a signal handler signal(SIGTERM, signal_handler); printf("SignalValue: %d\n", gSignalStatus); printf("Sending signal %d\n", SIGTERM); raise(SIGTERM); printf("SignalValue: %d\n", gSignalStatus); printf("Exit main()\n"); return 0; }
The output of the above code will be:
SignalValue: 0 Sending signal 15 SignalValue: 15 Exit main()
❮ C++ <csignal> Library