Capturing signals in C

You’ll need to use the signal.h library.

Here’s a working example in which I capture SIGINT and print a message to STDOUT:


void sig_handler(int signo)
    if (signo == SIGINT)
        write(0, "Hello\n", 6);

int main(void)
    signal(SIGINT, sig_handler);
    // Just to testing purposes
    return 0;

Browse More Popular Posts

Leave a Comment