System Calls Related to Signal Handling
As
stated in the introduction of this chapter, programs running in User
Mode are allowed to send and receive signals. This means that a set
of system calls must be defined to allow these kinds of operations.
Unfortunately, for historical reasons, several system calls exist
that serve essentially the same purpose. As a result, some of these
system calls are never invoked. For instance, sys_sigaction( )
and sys_rt_sigaction( )
are almost
identical, so the sigaction( )
wrapper function
included in the C library ends up invoking sys_rt_sigaction( )
instead of sys_sigaction( )
. We shall
describe some of the most significant POSIX system calls.
The kill( ) System Call
The kill(pid,sig)
system call is commonly used to
send signals; its corresponding service routine is the
sys_kill( )
function. The integer
pid
parameter has several meanings, depending on
its numerical value:
- pid > 0
The
sig
signal is sent to the process whose PID is equal topid
.- pid = 0
The
sig
signal is sent to all processes in the same group as the calling process.- pid = -1
The signal is sent to all processes, except swapper (PID 0), init (PID 1), and
current
.- pid < -1
The signal is sent to all processes in the process group -pid.
The sys_kill( )
function sets up a minimal
siginfo_t
table for the signal, and then invokes
kill_something_info( )
:
info.si_signo = sig; info.si_errno = 0; info.si_code = SI_USER; info._sifields._kill._pid = current->pid; info._sifields._kill._uid ...
Get Understanding the Linux Kernel, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.