SIGNAL(2) — Kubota Pacfic Computer Inc. (System Calls)
NAME
signal − specify what to do upon receipt of a signal
SYNOPSIS
#include <signal.h>
void (∗signal (sig, func))( )
int sig;
void (∗func)( );
DESCRIPTION
signal allows the calling process to choose one of three ways in which it is possible to handle the receipt of a specific signal. sig specifies the signal and func specifies the choice.
sig can be assigned any one of the following except SIGKILL:
SIGHUP01hangup
SIGINT02interrupt (rubout)
SIGQUIT03 [1]quit (ASCII FS)
SIGILL04 [1]illegal instruction (not reset when caught)
SIGTRAP05 [1]trace trap (not reset when caught)
SIGIOT06 [1]IOT instruction (obsolete)
SIGABRT06 [1]used by abort, replaces SIGIOT
SIGEMT07 [1]EMT instruction (obsolete)
SIGFPE08 [1]floating point exception
SIGKILL09kill (cannot be caught or ignored)
SIGBUS10 [1]bus error
SIGSEGV11 [1]segmentation violation
SIGSYS12 [1]bad argument to system call
SIGPIPE13write on a pipe with no one to read it
SIGALRM14alarm clock
SIGTERM15software termination signal
SIGUSR116user-defined signal 1
SIGUSR217user-defined signal 2
SIGCLD18 [2]death of a child
SIGPWR19 [2]power fail restart
SIGWIND20window change
SIGURG21urgent condition on an I/O channel
SIGPOLL22 [3]selectable event pending
SIGSTOP23sendable stop signal, not from tty
SIGTSTP24stop signal from tty
SIGTTIN25process stop by background tty read
SIGTTOU26process stop by background tty write
SIGCONT27continue a stopped process
SIGXCPU28exceeded CPU time limit
SIGXFSZ29exceeded file size limit
SIGVTALRM30virtual time alarm
SIGPROF31profiling time alarm
func is assigned one of three values: SIG_DFL, SIG_IGN, or a function address. SIG_DFL and SIG_IGN are defined in the include file 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.
The actions prescribed by the values of func are listed below:
SIG_DFL − terminate process upon receipt of a signal
Upon receipt of the signal sig, the receiving process is to be terminated with all of the consequences outlined in exit(2). See NOTE [1] below.
SIG_IGN − ignore signal
The signal sig is to be ignored.
Note: the signal SIGKILL cannot be ignored.
function address − catch signal
Upon receipt of the signal sig, the receiving process is to execute the signal-catching function pointed to by func. The signal number sig is passed as the first argument to the signal-catching function. Additional arguments are passed to the signal-catching function for hardware-generated signals as described in Note [4], below. Before entering the signal-catching function, the value of func for the caught signal is set to SIG_DFL unless the signal is SIGKILL, SIGTRAP, or SIGPWR.
Upon return from the signal-catching function, the receiving process resumes execution at the point it was interrupted.
When a signal that is to be caught occurs during a read(2), write(2), open(2), or an ioctl(2) system call on a slow device (like a terminal; but not a file), during a pause(2) or wait(2) that does not return immediately due to the existence of a previously stopped or zombie process, the signal catching function is executed and then the interrupted system call may return a −1 to the calling process with errno set to EINTR.
signal does not catch an invalid function argument, func, and results are undefined when an attempt is made to execute the function at the bad address.
Note: The signal SIGKILL cannot be caught.
A call to signal cancels a pending signal sig except for a pending SIGKILL signal.
signal fails if sig is an illegal signal number, including SIGKILL. [EINVAL]
NOTES
[1] 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 inherits the following properties:
a mode of 0666 modified by the file creation mask [see umask(2)]
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
[2] For the signals SIGCLD and SIGPWR, func is 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(2)].
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, and exit system calls as follows:
wait If the func value of 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.
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 proceeding 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.
[3] SIGPOLL is issued when a file descriptor corresponding to a STREAMS [see intro(2)] file has a "selectable" event pending. A process must specifically request that this signal be sent using the I_SETSIG ioctl call. Otherwise, the process never receives SIGPOLL.
[4] The handler routine to catch signals can be delared as follows:
handler(sig, code, junk, context)
int sig, code, junk
struct sigcontext ∗context;
Here, sig is the signal number. code is a value which further interprets sig; it may be one of the following:
SIGFPE
0: integer overflow
1: floating exception
SIGTRAP
CAUSESINGLE: single step
CAUSEBREAK: breakpoint instruction
The value of junk is the address of the handler routine itself. context is a pointer to the machine state at the time of the exception. It is defined in /usr/include/sys/signal.h.
For the Stardent 1500: On floating point exceptions, the FPU is halted. Explicit user action of restarting the FPU will be necessary. For the Stardent 3000: On floating point exceptions, the FPU state is preserved in the context structure, and the FPU state is made idle and ready for use.
SEE ALSO
intro(2), kill(1), kill(2), pause(2), ptrace(2), wait(2), setjmp(3C), sigset(2)
DIAGNOSTICS
Upon successful completion, signal returns the previous value of func 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 the include file signal.h.
September 02, 1992