0

I've read alot on here about catching signals in C. But all code examples I've seen are watching for specific signals. Like SIGINT or SIGTERM.

Say that I have a program in which I want to check for signals. And I use this function in my main function: signal(SIGINT, sighandler); Where sighandler is my own defined function that looks something like this:

void sighandler(int signo)
{
    printf("\n Recieved signal %d", signo);
    signal(SIGINT, sighandler);
}

But If I want to check for more signals do I have to add more checks in my main function function like:

...
signal(SIGINT, sighandler);
signal(SIGTERM, sighandler);
signal(SIGILL, sighandler);
...

Or can I use like a wildcard(?) to catch multiple exceptions like say: signal(SIGALL, sighandler);. And then check in my function what has been sent?

void sighandler(int signo)
{
    printf("\n Recieved signal %d", signo);
    signal(signo, sighandler);
}

I hope my question is understandable and that I am not missing something very very obvious.

mrfr
  • 1,724
  • 2
  • 23
  • 44

0 Answers0