Function raise () in C

Function int raise (int sig) in Library C creates sig signal. The sig parameter is compatible with the SIG macro.

Function int raise (int sig) in Library C creates sig signal. The sig parameter is compatible with the SIG macro.

Declare the function raise () in C

Below is the declaration for signal () function in C:

 int raise ( int sig ) 

Parameters

sig - This is the signal number to gửi. Following are few important Standard signal constantstrong Library C:

macrosignalSIGABRT (Signal Abort) Abnormal termination, such as initialized by abort function SIGFPE (Signal Floating-Point Exception) Operation related to arithmetic is not correct, such as dividing by zero or overflow (overflow) SIGILL (Signal Illegal Instruction) An invalid SIGINT (Signal Interrupt) instruction instruction Interrupt signal, usually created by the user application SIGSEGV (Signal Segmentation Violation) Invalid access to storage, when a program try to read or write outside the memory allocated to it SIGTERM (Signal Terminate) The end request is sent to the program

Returns the value

This function returns 0 if successful. If not, the function returns a value other than 0.

For example

The following C program illustrates the usage of the signal () function in C:

 #include #include #include void signal_catchfunc ( int ); int main () { int ret ; ret = signal ( SIGINT , signal_catchfunc ); if ( ret == SIG_ERR ) { printf ( "Error: khong the thiet lap signal handler.n" ); exit ( 0 ); } printf ( "Chuan bi tao mot tin hieun" ); ret = raise ( SIGINT ); if ( ret != 0 ) { printf ( "Error: khong the tao tin hieu SIGINT.n" ); exit ( 0 ); } printf ( "Dang thoat .n" ); return ( 0 ); } void signal_catchfunc ( int signal ) { printf ( "!!! Tin hieu da duoc bat !!!n" ); } 

Compiling and running the above C program will result:

 Chuan bi tao mot tin hieu !!! Tin hieu da duoc bat !!! Dang thoat . 

According to Tutorialspoint

Previous post: signal.h in C

Next lesson: Function signal () in C

5 ★ | 1 Vote