sigset, sighold, sigrelse, sigignore, sigpause --
signal management routines
Syntax
cc . . . -lc
#include <signal.h>
void (*sigset (sig, func))()
int sig;
void (*func)();
int sighold (sig)
int sig;
int sigrelse (sig)
int sig;
int sigignore (sig)
int sig;
int sigpause (sig)
int sig;
Description
sigset-
specifies signal action to be taken
sighold-
holds a signal until released or discarded
sigrelse-
release a held signal
sigignore-
sets the action for signal to SIG_IGN
sigpause-
suspends the calling process until it receives a signal
These functions provide signal management for application processes.
The sigset system call
specifies the system signal action to be taken upon receipt of signal
sig.
This action is either calling a process signal-catching handler
func or performing a system-defined action.
sig
can be assigned any one of the following values except SIGKILL
and SIGSTOP.
Machine- or implementation-dependent signals are not included
(see Notes below).
Each value of sig is a macro, defined in <signal.h>,
that expands to an integer constant expression.
Signal
Value
Description
XPG 3
POSIX
ANSI
SIGHUP
01
hangup
SIGINT
02
interrupt
SIGQUIT
03
[1]
quit
SIGILL
04
[1]
illegal instruction (not reset when caught)
SIGTRAP
05
[1]
trace trap (not reset when caught)
SIGIOT
06
[1]
IOT instruction
SIGABRT
06
[1]
used by abort, replaces SIGIOT
SIGEMT
07
[1]
EMT instruction
SIGFPE
08
[1]
floating point exception
SIGKILL
09
kill (cannot be caught or ignored)
SIGBUS
10
[1]
bus error
SIGSEGV
11
[1]
segmentation violation
SIGSYS
12
[1]
bad argument to system call
SIGPIPE
13
write on a pipe with no one to read it
SIGALRM
14
alarm clock
SIGTERM
15
software termination signal
SIGUSR1
16
user-defined signal 1
SIGUSR2
17
user-defined signal 2
SIGCLD
18
[3]
death of a child
SIGCHLD
18
[3]
synonym for SIGCLD
SIGPWR
19
[3]
power fail
SIGWINCH
20
window change
SIGPOLL
22
[4]
selectable event pending
SIGSTOP
23
[2]
sendable stop signal not from tty
SIGTSTP
24
[2]
stop signal from tty
SIGCONT
25
[2]
continue a stopped process
SIGTTIN
26
[2]
background tty read attempt
SIGTTOU
27
[2]
background tty write attempt
SIGVTALRM
28
virtual timer alarm
SIGPROF
29
profile alarm
The following values for the system-defined actions of
func are also defined in <signal.h>.
Each is a macro that expands to a constant expression
of type pointer to function returning void
and has a unique value that matches no declarable function.
SIG_DFL (default system action)
Upon receipt of the signal sig,
the receiving process is to be terminated with
all of the consequences outlined in
exit(S-osr5).
Those signals with a [1] or a [2]
are exceptions to this rule. Their default behavior is described in the
corresponding Notes section below.
SIG_IGN (ignore signal)
Any pending signal sig
is discarded and the system signal action
is set to ignore future occurrences of
this signal type.
SIG_HOLD (hold signal)
The signal sig is to be held upon receipt.
Any pending signal of this type remains held.
Only one signal of each type is held.
Otherwise, func
must be a pointer to a function, the signal-catching handler,
that is to be called when signal sig occurs.
In this case, sigset
specifies that the process calls this function upon
receipt of signal sig.
Any pending signal of this type is released.
This handler address is retained across calls
to the other signal management functions listed here.
When a signal occurs, the signal number sig
is passed as the only argument to the signal-catching handler.
Before calling the signal-catching handler,
the system signal action is set to SIG_HOLD.
During normal return from the signal-catching handler,
the system signal action is restored to func
and any held signal of this type released.
If a non-local goto (longjmp)
is taken, then the signal remains held, and sigrelse
must be called to restore the system signal action
and release any held signal of this type.
If a signal-catching function is invoked, how it effects the interrupted
function is described by each individual function. See the X/Open Portability Guide, Issue 3, 1989
sigaction(S-osr5)
section
``Signal Effects on Other Functions'', for further information.
sighold and sigrelse
are used to establish critical regions of code.
sighold is analogous to raising the priority level
and deferring or holding a signal until the priority is lowered by
sigrelse.
sigrelse
restores the system signal action to that specified previously by
sigset.
sigignore sets the action for signal
sig to SIG_IGN (see above).
sigpause
suspends the calling process until it receives a signal,
the same as
pause(S-osr5).
However, if the signal sig
had been received and held, it is released and the
system signal action taken.
This system call is useful for testing variables
that are changed on the occurrence of a signal.
The correct usage is to use sighold
to block the signal first, then test the variables.
If they have not changed, then call sigpause
to wait for the signal.
sigset fails if one or more of the following is true:
[EINVAL]
sig
is an illegal signal number (including SIGKILL)
or the default handling of sig cannot be changed.
[EINTR]
A signal was caught during the system call sigpause.
Diagnostics
Upon successful completion, sigset
returns the previous value of the system signal action for the specified signal
sig.
Otherwise, a value of SIG_ERR is returned and
errno is set to indicate the error.
SIG_ERR is defined in
<signal.h>.
For the other functions, upon successful completion,
a value of 0 is returned.
Otherwise, a value of -1 is returned and
errno is set to indicate the error.
Notes
If
SIG_DFL
is assigned for these signals, in addition to the process being terminated,
a ``core image'' is constructed in the current working directory
of the process, if the following conditions are met:
The effective user ID
and the real user ID
of the receiving process are equal.
An ordinary file named
core
exists and is writable or can be created.
If the file must be created, it has the following properties:
a mode of 0666 modified by the file creation mask
(see
umask(S-osr5)).
a file owner
ID
that is the same as the effective user
ID
of the receiving process.
a file group
ID
that is the same as the effective group
ID
of the receiving process.
For the signals
SIGSTOP, SIGTSTP, SIGTTIN, and SIGTTOU
the default action is to stop the process
rather than to terminate the process.
The distinction is that a stopped process can be
started again with a SIGCONT whereas a
terminated process cannot be restarted
under any circumstance.
For the SIGCONT
signal, the default action is to
continue the process if it is
stopped, otherwise it is ignored.
For the signals SIGCLD and SIGPWR,
the signal-handling function
is, again, assigned one of three values:
SIG_DFL, SIG_IGN, or a function address.
The actions prescribed by these values are:
SIG_DFL (ignore signal)
The signal is to be ignored.
SIG_IGN (ignore signal)
The signal is to be ignored.
Also, if sig is SIGCLD,
the calling process's child processes
does not create zombie processes when they terminate
(see
exit(S-osr5)).
function address (catch signal)
If the signal is SIGPWR,
the action to be taken is the same
as that described above for func
equal to function address.
The same is true if the signal is SIGCLD
with one exception:
while the process is executing the signal-catching function,
any received SIGCLD signals are ignored.
(This is the default action.)
In addition, SIGCLD affects the
wait, waitpid, and exit
system calls as follows:
wait
If the func for SIGCLD
is set to SIG_IGN
and a wait is executed,
the wait
blocks until all of the calling process's child processes terminate;
it then returns a value of -1 with
errno set to ECHILD
waitpid
If the func for SIGCLD
is set to SIG_IGN
and a waitpid is executed,
the waitpid
blocks until all of the calling process's child processes terminate;
it then returns a value of -1 with
errno set to ECHILD.
However, if the WNOHANG option
is specified, waitpid does not block.
exit
If in the exiting process's parent process
the func value of SIGCLD
is set to SIG_IGN,
the exiting process does not create a zombie process.
When processing a pipeline, the shell
makes the last process in the pipeline the parent of the preceding processes.
A process that may be piped into in this manner (and thus become the parent
of other processes) should take care not to set
SIGCLD to be caught.
SIGPOLL
is issued when a file descriptor corresponding
to a STREAMS (see
Intro(S-osr5))
file has a ``selectable'' event pending.
A process must specifically request that this signal be sent
using the I_SETSIGioctl call.
Otherwise, the process never receives
SIGPOLL. SIGPOLL is defined to have a value of
20 if used in cross-compiling for XENIX.
For portability, applications should use only the symbolic
names of signals rather than their values and use only the
set of signals defined here.
The action for the signal SIGKILL
cannot be changed from the default system action.
Other implementations of UNIX System V
may have other implementation-defined signals.
Also, additional implementation-defined arguments may be passed
to the signal-catching handler for hardware-generated signals.
For certain hardware-generated signals,
it may not be possible to resume execution
at the point of interruption.
The signal type SIGSEGV
is reserved for the condition that occurs on
an invalid access to a data object.
The other signal management functions,
signal(S-osr5)
and
pause(S-osr5),
should not be used in conjunction with these routines
for a particular signal type.