listening to posix style signals

Dec 8, 2011   coding

A quick self reminder

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

void handler(int signal)
    printf("Signal: %s\n", strsignal(signal));
    if (signal == SIGABRT)
    raise(SIGKILL); // can't be caught or ignored

int main(int argc, char *argv[])
    signal(SIGABRT, handler); // Abort
    signal(SIGFPE, handler);  // Floating-Point Exception
    signal(SIGILL, handler);  // Illegal Instruction
    signal(SIGINT, handler);  // Interrupt
    signal(SIGSEGV, handler); // Segmentation Violation
    signal(SIGTERM, handler); // Terminate
    signal(SIGQUIT, handler); // Terminal quit

    printf("Hello Crazy World!\n");

    raise(SIGABRT); // raise Abort

    printf("I am never going to be printed...\n");

    return 0;