The Linux Programming Interface

(nextflipdebug5) #1

458 Chapter 22


On Linux, this call returns –1. The reason for this is that Linux employs a different
model for limiting the number of realtime signals that may be queued to a process. In
Linux versions up to and including 2.6.7, the kernel enforces a system-wide limit on the
total number of realtime signals that may be queued to all processes. This limit can be
viewed and (with privilege) changed via the Linux-specific /proc/sys/kernel/rtsig-max
file. The default value in this file is 1024. The number of currently queued realtime sig-
nals can be found in the Linux-specific /proc/sys/kernel/rtsig-nr file.
Starting with Linux 2.6.8, this model was changed, and the aforementioned /proc
interfaces were removed. Under the new model, the RLIMIT_SIGPENDING soft resource
limit defines a limit on the number of signals that can be queued to all processes
owned by a particular real user ID. We describe this limit further in Section 36.3.

Using realtime signals
In order for a pair of processes to send and receive realtime signals, SUSv3
requires the following:

z The sending process sends the signal plus its accompanying data using the
sigqueue() system call.

A realtime signal can also be sent using kill(), killpg(), and raise(). However,
SUSv3 leaves it as implementation-dependent whether realtime signals sent
using these interfaces are queued. On Linux, these interfaces do queue real-
time signals, but on many other UNIX implementations, they do not.

z The receiving process establishes a handler for the signal using a call to
sigaction() that specifies the SA_SIGINFO flag. This causes the signal handler to be
invoked with additional arguments, one of which includes the data accompany-
ing the realtime signal.

On Linux, it is possible to queue realtime signals even if the receiving process
doesn’t specify the SA_SIGINFO flag when establishing the signal handler
(although it is not then possible to obtain the data associated with the signal in
this case). However, SUSv3 doesn’t require implementations to guarantee this
behavior, so we can’t portably rely on it.

22.8.1 Sending Realtime Signals.......................................................................


The sigqueue() system call sends the realtime signal specified by sig to the process
specified by pid.

The same permissions are required to send a signal using sigqueue() as are required
with kill() (see Section 20.5). A null signal (i.e., signal 0) can be sent, with the same
meaning as for kill(). (Unlike kill(), we can’t use sigqueue() to send a signal to an
entire process group by specifying a negative value in pid.)

#define _POSIX_C_SOURCE 199309
#include <signal.h>

int sigqueue(pid_t pid, int sig, const union sigval value);
Returns 0 on success, or –1 on error
Free download pdf