Function name : raise
Header file : <stdio.h>
Function prototype : int raise(int sig);
Function : Send a signal to the executing program
Parameters : the name of the signal to be sent
Return value : 0 on success, non-0 on failure
Supplement : SIGABRT (Signal Abort) program terminates abnormally.
SIGFPE (Signal Floating-Point Exception) Arithmetic operation error, such as division by 0 or overflow (not necessarily floating point operation).
SIGILL (Signal Illegal Instruction) An illegal function image, such as an illegal instruction, usually caused by a variation in the code or an attempt to execute data.
SIGINT (Signal Interrupt) Interrupt signal, such as ctrl-C, is usually generated by the user.
SIGSEGV (Signal Segmentation Violation) Illegal access to memory, such as accessing a non-existent memory unit.
SIGTERM (Signal Terminate) Termination request signal sent to this program.
Program example: Determine whether division is meaningful. When the divisor is 0, send a signal
#include<signal.h>#include<stdio.h>intmain(void){inta,b;a=10;b=0;printf(begin-----n);if(b==0) raise(SIGFPE);//If the divisor is 0, send a signal to terminate the program a=a/b;printf(begin-----n);return0;}
Running results
begin-----