❖
SIGKILL ( 9) - immediate termination of the program (this signal
cannot be changed position)
❖
SIGUSR 1 SIGUSR 2 (10,12) - user signals that can use
applications
❖
SIGTERM (15) - Offer the program to shut down (this signal,
unlike SIGKILL, may be ignored)
The default action for all of these signals, except for SIGSEGV, is to
terminate the program (
an additional memory dump ( core dump ) is
generated for SIGSEGV - a file that stores the image of the process address
space for later analysis).
Setting The Signal Layout
A sigaction () system call is used to set the signal disposition.
#include
int sigaction (int signum, // signal numbe r
struct sigaction * action, // new layout
struct sigaction * old_action); // return the previous disposition
The exposition is described using the sigaction structure with the following
fields:
❖
sa _ handler - pointer to the signal processor function
❖
sa _ mask - the signal mask that specifies which signals will be
blocked inside the processor
❖
sa_flag - additional checkboxes
Limit to zeroing sa _ mask and sa _ flag (without blocking any signal):
struct sigaction action = {0};
The sa _ handler field should be set as a pointer to a previously declared
function that looks like this:
void user_handler (int signum)
{
// signal processing
}
This feature becomes a signal processor. The signum parameter determines
which signal is sent to the handler (the same
handler can be logged for
multiple signals by several sigaction () calls ). After logging in, the handler
will always be called when it receives the appropriate signal:
#include
void sigint_handler (int signum)
{
// SIGINT processing
}
// …… ..
action.sa_handler = sigint_handler;
sigaction (SIGINT, & action, 0);
If we need to organize the wait for the signal, the simplest way is to open a
system call pause (). In this case, the process enters standby mode, from
which it will output any signal:
// ask the handlers for help with sigaction ()
pause (); // wait for a signa l