raise - C signal.h

C examples for signal.h:raise

Type

function

From

<csignal>

Description

Generates a signal which is handled as specified by function signal.

Prototype

int raise (int sig);

Parameters

Parameter Description
sig The signal value to raise.

The following macro constant expressions identify standard signal values:

macro stands forsignal
SIGABRT Signal Abort Abnormal termination.
SIGFPE Signal Floating-Point ExceptionErroneous arithmetic operation.
SIGILL Signal Illegal Instruction due to a corruption in the code or to an attempt to execute data.
SIGINT Signal InterruptGenerally generated by the application user.
SIGSEGV Signal Segmentation Violation Invalid access to storage when trying to access outside the memory it is allocated for it.
SIGTERM Signal Terminate Termination request sent to program.

Return Value

On success, returns zero.

On error, a value different from zero otherwise.

Demo Code


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

sig_atomic_t signaled = 0;//from   ww  w . j  av  a  2 s . c om

void my_handler (int param){
  signaled = 1;
}

int main (){
  void (*prev_handler)(int);

  prev_handler = signal (SIGINT, my_handler);

  raise(SIGINT);

  printf ("signaled is %d.\n",signaled);

  return 0;
}

Related Tutorials