gno/usr.man/man2/signal.2

238 lines
7.5 KiB
Groff

.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)signal.3 8.3 (Berkeley) 4/19/94
.\"
.TH SIGNAL 3 "19 January 1997" GNO "System Calls"
.SH NAME
.BR signal
\- simplified software signal facilities
.SH SYNOPSIS
.br
#include <signal.h>
.sp 1
void (*\fBsignal\fR (int \fIsig\fR, void (*\fIfunc\fR)(int, int)))(int, int);
.sp 1
or in GNO's equivalent but easier to read typedef'd version:
.sp 1
typedef void (*sig_t) (int, int)
.sp 1
sig_t
\fBsignal\fR(int \fIsig\fR, sig_t \fIfunc\fR);
.SH DESCRIPTION
Signals allow the manipulation of a process from outside its
domain as well as allowing the process to manipulate itself or
copies of itself (children). There are two general types of signals:
those that cause termination of a process and those that do not.
Signals which cause termination of a program might result from
an irrecoverable error or might be the result of a user at a terminal
typing the `interrupt' character.
Signals are used when a process is stopped because it wishes to access
its control terminal while in the background (see
.BR tty (4)).
Signals are optionally generated
when a process resumes after being stopped,
when the status of child processes changes,
or when input is ready at the control terminal.
.LP
Most signals result in the termination of the process receiving them
if no action
is taken; some signals instead cause the process receiving them
to be stopped, or are simply discarded if the process has not
requested otherwise.
The
.BR signal
function allows for a signal to be caught, to be ignored, or to generate
an interrupt, except for
.BR SIGCONT
(which cannot be blocked), and
.BR SIGKILL
and
.BR SIGSTOP
(which cannot be caught, blocked, or ignored).
.LP
These signals are defined in the file <signal.h>:
.RS
.nf
Name Default Action Description
SIGHUP termination terminal line hangup
SIGINT termination interrupt program
SIGQUIT termination quit program
SIGILL termination illegal instruction
SIGTRAP termination trace trap
SIGABRT termination abort (generated by \fBabort\fR(3))
SIGEMT termination emulator trap
SIGFPE termination arithmetic exception
SIGKILL termination kill program
SIGBUS termination bus error
SIGSEGV termination segmentation fault
SIGSYS termination bad argument to system call
SIGPIPE termination write on a socket with no readers
SIGALRM termination real-time timer expired
SIGTERM termination software termination
SIGURG discarded urgent condition present on socket
SIGSTOP stop stop
SIGTSTP stop stop signal from keyboard
SIGCONT discarded continue after stop
SIGCHLD discarded child status has changed
SIGCLD discarded SYSV name for SIGCHLD
SIGTTIN stop background read attempted
SIGTTOU stop background write attempted
SIGIO discarded input/output possible on a file descriptor
SIGPOLL discarded SYSV name for SIGIO
SIGXCPU termination exceeded CPU time limit
SIGUSR1 termination user defined signal 1
SIGUSR2 termination user defined signal 2
.fi
.RE
.LP
The
.I func
procedure allows a user to choose the action upon receipt of a signal.
To set the default action of the signal to occur as listed above,
.I func
should be
.BR SIG_DFL .
A
.BR SIG_DFL
resets the default action.
To ignore the signal
.I func
should be
.BR SIG_IGN .
This will cause subsequent instances of the signal to be ignored
and pending instances to be discarded. If
.BR SIG_IGN
is not used,
further occurrences of the signal are
automatically blocked and
.I func
is called.
.LP
The handled signal is unblocked with the
function returns and
the process continues from where it left off when the signal occurred.
\fIUnlike previous Unix signal facilities, the handler
func() remains installed after a signal has been delivered.\fR
This behavior remains unchanged from GNO v2.0.4.
.LP
For some system calls, if a signal is caught while the call is
executing and the call is prematurely terminated,
the call is automatically restarted.
The affected system calls include
.BR read (2),
.BR write (2),
.BR sendto (2),
.BR recvfrom (2),
.BR sendmsg (2)
and
.BR recvmsg (2)
on a communications channel or a low speed device
and during a
.BR ioctl (2)
or
.BR wait (2).
However, calls that have already committed are not restarted,
but instead return a partial success (for example, a short read count).
.LP
When a process which has installed signal handlers forks,
the child process inherits the signals.
All caught signals will be reset to their default action by a call
to one of the
.BR execve (2)
family of functions;
ignored signals remain ignored.
.SH NOTES
As can be surmised from the prototype above,
.IR func
should be defined as follows:
.RS
.sp 1
void \fIfunc\fR(int \fIsig\fR, int \fIcode\fR)
.sp 1
.RE
.I sig
is the signal that will invoke the handler, and
.I code
is additional information about the interrupt condition. Currently,
.I code
is always zero. The handler should probably also be compiled using the
.B "#pragma databank 1"
directive, in the event
.I func
is not in the same bank as the C global data segment
.RI ( func
is called with the data bank equal to the program bank).
.LP
ORCA/C already provides a
.BR signal
function, but it doesn't do very much. GNO's <signal.h> file replaces
the one that comes with ORCA/C.
.SH RETURN VALUES
The previous action is returned on a successful call.
Otherwise, \-1 is returned and the global variable
.IR errno
is set to indicate the error.
.SH ERRORS
.BR Signal
will fail and no action will take place if one of the
following occur:
.RS
.IP \fBEINVAL\fR
.IR Sig
is not a valid signal number.
.IP \fBEINVAL\fR
An attempt is made to ignore or supply a handler for
.BR SIGKILL
or
.BR SIGSTOP .
.IP \fBEINVAL\fR
An attempt is made to ignore
.BR SIGCONT
(by default
.BR SIGCONT
is ignored).
.SH SEE ALSO
.BR kill (1),
.BR execve (2),
.BR fork (2),
.BR kill (2),
.BR sigblock (2),
.BR sigsetmask (2),
.BR wait (2),
.BR tty (4)
.SH HISTORY
A
.BR signal
facility appeared in 4.0BSD.