HP-UX Reference (11i v2 07/12) - 2 System Calls (vol 5)

s
signal(2) signal(2)
If disp is not SIG_DFL, SIG_IGN
,orSIG_HOLD, it must be a pointer to a function, the signal-catching
handler, that is called when signal sig occurs. Before calling the signal-catching handler, the system signal
action of sig is set to
SIG_HOLD. Any pending signal of this type is released. This handler address is
retained across calls to the other signal management functions listed here. Upon receipt of signal sig, the
receiving process executes the signal-catching handler pointed to by disp.
During a normal return from the signal-catching handler, the system signal action is restored to disp and
any held signal of this type is released. If a non-local goto (longjmp(3C)) is taken,
sigrelse() must be
called to restore the system signal action to disp and release any held signal of this type.
For either signal(2) or sigset(3C), if the action for the
SIGCHLD signal is set to SIG_IGN, child processes
of the calling processes will not be transformed into zombie processes when they terminate. If the calling
process subsequently waits for its children, and the process has no unwaited for children that were
transformed into zombie processes, it will block until all of its children terminate, and
wait(), wait3(),
waitid() and waitpid() will fail and set errno
to [ECHILD].
RETURN VALUE
If the request can be honored,
signal()
returns the value of func() for the most recent call to sig-
nal()
for the specified signal sig. Otherwise, SIG_ERR is returned and a positive value is stored in
errno.
Upon successful completion, sigset() returns SIG_HOLD if the signal had been blocked and the signals
previous disposition if it had not been blocked. Otherwise, SIG_ERR is returned and errno is set to indi-
cate the error.
For all other functions, upon successful completion, 0 is returned. Otherwise, -1 is returned and
errno is
set to indicate the error.
ERRORS
The
signal() function will fail if:
[EINVAL] The sig argument is not a valid signal number or an attempt is made to catch a signal
that cannot be caught or ignore a signal that cannot be ignored.
The signal() function may fail if:
[EINVAL] An attempt was made to set the action to
SIG_DFL for a signal that cannot be caught
or ignored (or both).
The
sigset() function will fail if:
[EINVAL] The sig argument is an illegal signal number.
[EINVAL] An attempt is made to ignore, hold, or supply a handler for a signal that cannot be
ignored, held, or caught; see signal(5).
[EFAULT] The func argument points to memory that is not a valid part of the process address
space. Reliable detection of this error is implementation-dependent.
The sighold() , sigrelse() , sigignore() , and sigpause() functions will fail if:
[EINVAL] The sig argument is an illegal signal number.
[EINVAL] An attempt is made to ignore, hold, or supply a handler for a signal that cannot be
ignored, held, or caught; see signal(5).
The sigpause() returns when the following occurs:
[EINTR] A signal was caught.
APPLICATION USAGE
The sigaction() function provides a more comprehensive and reliable mechanism for controlling sig-
nals; new applications should use sigaction() rather than signal().
The sighold() function, in conjunction with sigrelse() or sigpause() , may be used to establish
critical regions of code that require the delivery of a signal to be temporarily deferred.
The sigsuspend() function should be used in preference to sigpause() for broader portability.
The sigpause() function suspends the calling process until it receives an unblocked signal. If the signal
sig is held, it is released before the process pauses. sigpause() is useful for testing variables that are
changed when a signal occurs. For example, sighold() should be used to block the signal first, then test
420 Hewlett-Packard Company 3 HP-UX 11i Version 2: December 2007 Update