your resources to programming and free tutition


C++ soon here!
VB - soon here!




Next Back


<signal.h>        -        Signal handling

jump to: demonstration of <signal.h>

This header provides facilities for handling exceptional conditions including interrupts and run-time errors.

int raise(int sig);

This function raise sends a signal, sig to the current process. The default action for that signal will be taken unless a new action was defined previously by a call to signal. The return value is 0 if this call is successful and non-zero otherwise.

void (*signal(int sig, void(*funct) (int)))(int);

This function signal sets the signal handler for signal sig to the value func. The function returns the previous value of the signed handler. If an error occurred, a value of SIG_ERR is returned and errno is set to EINVAL, including an invalid value for sig.

The argument sig can take any one of the following values defined in <signal.h>

SIGINT interrupt - corresponds to DOS 3.x int 23H 1
SIGILL illegal op code 2
SIGFPE floating point error 3
SIGSEGV segment violation 4
SIFTERM software termination signal from kill 5
SIGABRT abnormal termination triggered by abort call 6

The argument funct must be one of the following constants or the function address of a user defined signal handler.

SIG_DFL default signal action 1
SIG_IGN ignore 2


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

void warninig(void)
    printf("interrupt - Ctrl C pressed\n");

void abort_program(void)
    printf("program termination - raised SIGABRT\n");

int main(void);
    signal(SIGABRT, abort_program);

    return 0;


interrupt - Ctrl C pressed
program termination - raised SIGABRT

go to <stdarg.h>      back to top        back to main