mgus
mgus

Reputation: 808

How can a UNIX process ignore system signals?

Every time I press Ctrl+C inside the terminal a SIGINT signal is sent to the process. But what happens sometimes to the process and it is not responding to the signal? Basically, I'm asking about how can a process ignore the signal theoretically?

Upvotes: 3

Views: 1342

Answers (2)

sgros
sgros

Reputation: 180

You should install signal handler. The simplest one is:

#include <signal.h>
...
/* Put this somewhere at the beginning of your code */
sigignore(SIGINT);

This will cause the specified signal (SIGINT) to be ignored. Alternatively, you can have some function called when signal occurs:

void function(int sig)
{
    // do something
}

// Somewhere at the beginning of your code put this...
sigset(SIGINT, function);    

See details in corresponding manual pages. There are also more complex functions to manipulate signals, e.g. sigaction.

Upvotes: 4

Ian Roberts
Ian Roberts

Reputation: 122364

With the exception of SIGKILL and SIGSTOP any process is free to install its own handler for any signal, which can respond however it likes (up to and including ignoring the signal completely).

Upvotes: 4

Related Questions