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.
10.4.1 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:
The sig signal is sent to the process whose PID is equal to pid.
The sig signal is sent to all processes in the same group as the calling process.
The signal is sent to all processes, except swapper (PID 0), init (PID 1), and current.
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 = current->uid; return kill something info(sig, &info, pid);
The kill_something_info( ) function, in turn, invokes either send_sig_info( ) (to send the signal to a single process), or kill_pg_info( ) (to scan all processes and invoke send_sig_info( ) for each process in the destination group).
The kill( ) system call is able to send any signal, even the so-called real-time signals that have numbers ranging from 32 to 63. However, as we saw in the earlier section Section 10.2, the kill( ) system call does not ensure that a new element is added to the pending signal queue of the destination process, thus multiple instances of pending signals can be lost. Real-time signals should be sent by means of a system call like rt_sigqueueinfo( ) (see the later section Section 10.4.6).
System V and BSD Unix variants also have a killpg( ) system call, which is able to explicitly send a signal to a group of processes. In Linux, the function is implemented as a library function that uses the kill( ) system call. Another variation is raise( ), which sends a signal to the current process (that is, to the process executing the function). In Linux, raise() is implemented as a library function.
Was this article helpful?