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);