C library function - raise()



The C library function int raise(int sig) causes signal sig to be generated. The sig argument is compatible with the SIG macros.


Following is the declaration for signal() function.

int raise(int sig)


  • sig − This is the signal number to send. Following are few important standard signal constants −

macro signal
SIGABRT (Signal Abort) Abnormal termination, such as is initiated by the abort function.
SIGFPE (Signal Floating-Point Exception) Erroneous arithmetic operation, such as zero divide or an operation resulting in overflow (not necessarily with a floating-point operation).
SIGILL (Signal Illegal Instruction) Invalid function image, such as an illegal instruction. This is generally due to a corruption in the code or to an attempt to execute data.
SIGINT (Signal Interrupt) Interactive attention signal. Generally generated by the application user.
SIGSEGV (Signal Segmentation Violation) Invalid access to storage − When a program tries to read or write outside the memory it is allocated for it.
SIGTERM (Signal Terminate) Termination request sent to program.

Return Value

This function returns zero if successful, and non-zero otherwise.


The following example shows the usage of signal() function.

#include <signal.h>
#include <stdio.h>

void signal_catchfunc(int);

int main()
   int ret;

   ret = signal(SIGINT, signal_catchfunc);

   if( ret == SIG_ERR) 
      printf("Error: unable to set signal handler.\n");
   printf("Going to raise a signal\n");
   ret = raise(SIGINT);
   if( ret !=0 ) 
      printf("Error: unable to raise SIGINT signal.\n");


void signal_catchfunc(int signal)
   printf("!! signal caught !!\n");

Let us compile and run the above program to will produce the following result −

Going to raise a signal
!! signal caught !!