Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

376 Signals Chapter 10


10.20 sigqueueFunction


In Section 10.8 we said that most UNIX systems don’t queue signals.With the real-time
extensions to POSIX.1, some systems began adding support for queueing signals.With
SUSv4, the queued signal functionality has moved from the real-time extensions to the
base specification.
Generally a signal carries one bit of information: the signal itself. In addition to
queueing signals, these extensions allow applications to pass moreinformation along
with the delivery (recall Section 10.14). This information is embedded in asiginfo
structure. Along with system-provided information, applications can pass an integer or
apointer to a buffer containing moreinformation to the signal handler.
To use queued signals we have to do the following:


  1. Specify the SA_SIGINFOflag when we install a signal handler using the
    sigactionfunction. If we don’t specify this flag, the signal will be posted, but
    it is left up to the implementation whether the signal is queued.

  2. Provide a signal handler in thesa_sigactionmember of thesigaction
    structureinstead of using the usualsa_handlerfield. Implementations might
    allow us to use thesa_handlerfield, but we won’t be able to obtain the extra
    information sent with thesigqueuefunction.

  3. Use thesigqueuefunction to send signals.


#include <signal.h>
int sigqueue(pid_tpid,intsigno,const union sigvalvalue)
Returns: 0 if OK,−1 on error
Thesigqueuefunction is similar to thekillfunction, except that we can only
direct signals to a single process withsigqueue,and we can use thevalueargument to
transmit either an integer or a pointer value to the signal handler.
Signals can’t be queued infinitely.Recall theSIGQUEUE_MAXlimit from Figure2.9
and Figure2.11. When this limit is reached,sigqueuecan fail witherrnoset to
EAGAIN.
With the real-time signal enhancements, a separate set of signals was introduced for
application use. These arethe signal numbers betweenSIGRTMINandSIGRTMAX,
inclusive. Be awarethat the default action for these signals is to terminate the process.
Figure10.30 summarizes the way queued signals differ in behavior among the
implementations covered in this text.

FreeBSD Linux Mac OS X Solaris
Behavior SUS 8.0 3.2.0 10.6.8 10

supportssigqueue ••••
queues other signals besidesSIGRTMINtoSIGRTMAX optional • •
queues signals even if the caller doesn’t use theSA_SIGINFO optional • •
flag

Figure 10.30Behavior of queued signals on various platforms
Free download pdf