C Function Raise
# C Library Function - raise()\n\n[ C Standard Library - ](#)\n\n## Description\n\nThe C library function **int raise(int sig)** causes signal **sig** to be generated. The **sig** parameter is compatible with the SIG macros.\n\nThe `raise` function is a function in the C standard library used to send a signal to the current process. It is defined in the `` header file and allows a program to send a signal to itself to trigger the corresponding signal handler.\n\n## Declaration\n\nBelow is the declaration of the raise() function.\n\n```c\nint raise(int sig)\n\n## Parameters\n\n* **sig** -- The signal code to be sent. Below are some important standard signal constants:\n\n| Macro | Signal |\n| --- | --- |\n| SIGABRT | (Signal Abort) Abnormal termination of the program. |\n| SIGFPE | (Signal Floating-Point Exception) Arithmetic error, such as division by zero or overflow (not necessarily a floating-point operation). |\n| SIGILL | (Signal Illegal Instruction) Illegal function image, such as an illegal instruction, usually caused by a variant in the code or an attempt to execute data. |\n| SIGINT | (Signal Interrupt) Interrupt signal, such as ctrl-C, usually generated by the user. |\n| SIGSEGV | (Signal Segmentation Violation) Illegal access to memory, such as accessing a non-existent memory unit. |\n| SIGTERM | (Signal Terminate) Termination request signal sent to this program. |\n\n## Return Value\n\nIf successful, this function returns zero, otherwise it returns a non-zero value.\n\n## Example\n\nThe following example demonstrates the usage of the raise() function.\n\n## Example\n\n```c\n#include\n#include\n#include\n\nvoid signal_catchfunc(int);\n\nint main()\n{\n int ret;\n signal(SIGINT, signal_catchfunc);\n\n printf("Start generating a signal n");\n ret =raise(SIGINT);\n\n if(ret !=0)\n {\n printf("Error, cannot generate SIGINT signal n");\n exit(0);\n }\n\n printf("Exit....n");\n return 0;\n}\n\nvoid signal_catchfunc(int signal)\n{\n printf("Capture signal n");\n}\n\nLet us compile and run the above program, this will produce the following result:\n\nStart generating a signal\n!! Signal capture !!\nExit...\n\n[ C Standard Library - ](#)
YouTip