412 Chapter 20
The sigpending() system call returns the set of signals that are pending for the call-
ing process in the sigset_t structure pointed to by set. We can then examine set using
the sigismember() function described in Section 20.9.
If we change the disposition of a pending signal, then, when the signal is later
unblocked, it is handled according to its new disposition. Although not often used,
one application of this technique is to prevent the delivery of a pending signal by
setting its disposition to SIG_IGN, or to SIG_DFL if the default action for the signal is
ignore. As a result, the signal is removed from the process’s set of pending signals
and thus not delivered.
20.12 Signals Are Not Queued
The set of pending signals is only a mask; it indicates whether or not a signal has
occurred, but not how many times it has occurred. In other words, if the same sig-
nal is generated multiple times while it is blocked, then it is recorded in the set of
pending signals, and later delivered, just once. (One of the differences between
standard and realtime signals is that realtime signals are queued, as discussed in
Section 22.8.)
Listing 20-6 and Listing 20-7 show two programs that can be used to observe that
signals are not queued. The program in Listing 20-6 takes up to four command-line
arguments, as follows:
$ ./sig_sender PID num-sigs sig-num [sig-num-2]
The first argument is the process ID of a process to which the program should send
signals. The second argument specifies the number of signals to be sent to the tar-
get process. The third argument specifies the signal number that is to be sent to
the target process. If a signal number is supplied as the fourth argument, then the
program sends one instance of that signal after sending the signals specified by the
previous arguments. In the example shell session below, we use this final argument
to send a SIGINT signal to the target process; the purpose of sending this signal will
become clear in a moment.
Listing 20-6: Sending multiple signals
–––––––––––––––––––––––––––––––––––––––––––––––––––––– signals/sig_sender.c
#include <signal.h>
#include "tlpi_hdr.h"
int
main(int argc, char *argv[])
{
int numSigs, sig, j;
pid_t pid;
if (argc < 4 || strcmp(argv[1], "--help") == 0)
usageErr("%s pid num-sigs sig-num [sig-num-2]\n", argv[0]);