O'Reilly logo

Hands-On System Programming with Linux by Kaiwan N Billimoria

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the sigaction system call to trap signals

The sigaction(2) system call is the right way to trap or catch signals; it's powerful, POSIX compliant, and can be used to hone your application's signal-handling superbly.

At a high level, the sigaction system call is used to register a signal handler for a given signal. If the signal's handler function was foo, we can use sigaction to change its signal handler to bar. As usual, there is a lot more we can specify as well, which has a powerful impact upon signal handling, and we shall come to all that shortly. Here is the signature:

#include <signal.h>int sigaction(int signum, const struct sigaction *act,              struct sigaction *oldact);
Feature Test Macro Requirements for glibc (see feature_test_macros(7) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required