English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C / C ++raise() function in

The functionraise()Used to send a signal to the program. Predefined functionsignal()is called. It is used to check whether the signal is to be ignored or the signal handler is to be called. This is declared in the "signal.h" header file. It returns zero otherwise returns a non-zero value.

This israise()C Language Syntax,

int raise(int signal)

Here,

Signal-the signal number to be called.

This israise()C Language Example,

Example

#include <signal.h>
#include <stdio.h>
void handler(int sig) {
   printf("Signal received: %d\n", sig);
}
int main() {
   signal(SIGILL, handler);
   printf("Sending signal: %d\n", SIGILL);
   raise(SIGILL);
   return 0;
}

Output result

Sending signal: 4
Signal received: 4

In the above program, the function handler was defined before the function,main(), defined the function handler in the main function,signal()And sent and received SIGILL (invalid instruction signal).

signal(SIGILL, handler);
printf("Sending signal: %d\n", SIGILL);
raise(SIGILL);