224 lines
8.0 KiB
HTML
224 lines
8.0 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>sigaction(2)</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<H1>sigaction(2)</H1>
|
|
<HR>
|
|
<PRE>
|
|
|
|
</PRE>
|
|
<H2>NAME</H2><PRE>
|
|
sigaction, signal - manage signal state and handlers
|
|
|
|
|
|
</PRE>
|
|
<H2>SYNOPSIS</H2><PRE>
|
|
<STRONG>#include</STRONG> <STRONG><signal.h></STRONG>
|
|
|
|
<STRONG>int</STRONG> <STRONG>sigaction(int</STRONG> <EM>sig</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>struct</STRONG> <STRONG>sigaction</STRONG> <STRONG>*</STRONG><EM>act</EM><STRONG>,</STRONG> <STRONG>struct</STRONG> <STRONG>sigaction</STRONG>
|
|
<STRONG>*</STRONG><EM>oact</EM><STRONG>)</STRONG>
|
|
<STRONG>void</STRONG> <STRONG>(*signal(int</STRONG> <EM>sig</EM><STRONG>,</STRONG> <STRONG>void</STRONG> <STRONG>(*</STRONG><EM>handler</EM><STRONG>)(int)))(int);</STRONG>
|
|
|
|
|
|
</PRE>
|
|
<H2>DESCRIPTION</H2><PRE>
|
|
<STRONG>Sigaction()</STRONG> is used to examine, set, or modify the attributes of a
|
|
signal. The argument <EM>sig</EM> is the signal in question. The <EM>act</EM> argument
|
|
points to a structure containing the new attributes of the signal, the
|
|
structure pointed to by <EM>oact</EM> will receive the old attributes that were in
|
|
effect before the call.
|
|
|
|
The <EM>act</EM> and <EM>oact</EM> arguments may be <STRONG>NULL</STRONG> to indicate that either no new
|
|
attributes are to be set, or that the old attributes are not of interest.
|
|
|
|
The structure containing the signal attributes is defined in <signal.h>
|
|
and looks like this:
|
|
|
|
<STRONG>struct</STRONG> <STRONG>sigaction</STRONG> <STRONG>{</STRONG>
|
|
<STRONG>void</STRONG> <STRONG>(*sa_handler)(int</STRONG> <STRONG>sig);</STRONG>
|
|
<STRONG>sigset_t</STRONG> <STRONG>sa_mask;</STRONG>
|
|
<STRONG>int</STRONG> <STRONG>sa_flags;</STRONG>
|
|
<STRONG>};</STRONG>
|
|
|
|
The <STRONG>sa_handler</STRONG> field contains the address of a signal handler, a function
|
|
that is called when the process is signalled, or one of these special
|
|
constants:
|
|
|
|
<STRONG>SIG_DFL</STRONG> Default signal handling is to be performed. This usually
|
|
means that the process is killed, but some signals may be
|
|
ignored by default.
|
|
|
|
<STRONG>SIG_IGN</STRONG> Ignore the signal.
|
|
|
|
The <STRONG>sa_mask</STRONG> field indicates a set of signals that must be blocked when
|
|
the signal is being handled. Whether the signal <EM>sig</EM> itself is blocked
|
|
when being handled is not controlled by this mask. The mask is of a
|
|
"signal set" type that is to be manipulated by the <STRONG><A HREF="../man3/sigset.3.html">sigset(3)</A></STRONG> functions.
|
|
|
|
How the signal is handled precisely is specified by bits in <STRONG>sa_flags</STRONG>. If
|
|
none of the flags is set then the handler is called when the signal
|
|
arrives. The signal is blocked during the call to the handler, and
|
|
unblocked when the handler returns. A system call that is interrupted
|
|
returns <STRONG>-1</STRONG> with <STRONG>errno</STRONG> set to <STRONG>EINTR</STRONG>. The following bit flags can be set
|
|
to modify this behaviour:
|
|
<STRONG>SA_RESETHAND</STRONG> Reset the signal handler to <STRONG>SIG_DFL</STRONG> when the signal is
|
|
caught.
|
|
|
|
<STRONG>SA_NODEFER</STRONG> Do not block the signal on entry to the handler.
|
|
|
|
<STRONG>SA_COMPAT</STRONG> Handle the signal in a way that is compatible with the the
|
|
old <STRONG>signal()</STRONG> call.
|
|
|
|
The old <STRONG>signal()</STRONG> signal system call sets a signal handler for a given
|
|
signal and returns the old signal handler. No signals are blocked, the
|
|
flags are <STRONG>SA_RESETHAND</STRONG> <STRONG>|</STRONG> <STRONG>SA_NODEFER</STRONG> <STRONG>|</STRONG> <STRONG>SA_COMPAT</STRONG>. New code should not use
|
|
<STRONG>signal()</STRONG>. Note that <STRONG>signal()</STRONG> and all of the <STRONG>SA_*</STRONG> flags are Minix
|
|
extensions.
|
|
|
|
Signal handlers are reset to <STRONG>SIG_DFL</STRONG> on an <STRONG><A HREF="../man2/execve.2.html">execve(2)</A></STRONG>. Signals that are
|
|
ignored stay ignored.
|
|
|
|
<STRONG>Signals</STRONG>
|
|
Minix knows about the following signals:
|
|
|
|
signal num notes description
|
|
|
|
SIGHUP 1 k Hangup
|
|
SIGINT 2 k Interrupt (usually DEL or CTRL-C)
|
|
SIGQUIT 3 kc Quit (usually CTRL-\)
|
|
SIGILL 4 kc Illegal instruction
|
|
SIGTRAP 5 xkc Trace trap
|
|
SIGABRT 6 kc Abort program
|
|
SIGFPE 8 k Floating point exception
|
|
SIGKILL 9 k Kill
|
|
SIGUSR1 10 k User defined signal #1
|
|
SIGSEGV 11 kc Segmentation fault
|
|
SIGUSR2 12 k User defined signal #2
|
|
SIGPIPE 13 k Write to a pipe with no reader
|
|
SIGALRM 14 k Alarm clock
|
|
SIGTERM 15 k Terminate (default for <STRONG><A HREF="../man1/kill.1.html">kill(1)</A></STRONG>)
|
|
SIGCHLD 17 pvi Child process terminated
|
|
SIGCONT 18 p Continue if stopped
|
|
SIGSTOP 19 ps Stop signal
|
|
SIGTSTP 20 ps Interactive stop signal
|
|
SIGTTIN 21 ps Background read
|
|
SIGTTOU 22 ps Background write
|
|
SIGWINCH 23 xvi Window size change
|
|
|
|
The letters in the notes column indicate:
|
|
|
|
|
|
|
|
|
|
|
|
<STRONG>k</STRONG> The process is killed if the signal is not caught.
|
|
|
|
<STRONG>c</STRONG> The signal causes a core dump.
|
|
|
|
<STRONG>i</STRONG> The signal is ignored if not caught.
|
|
|
|
<STRONG>v</STRONG> Only Minix-vmd implements this signal.
|
|
|
|
<STRONG>x</STRONG> Minix extension, not defined by POSIX.
|
|
|
|
<STRONG>p</STRONG> These signals are not implemented, but POSIX requires that they are
|
|
defined.
|
|
|
|
<STRONG>s</STRONG> The process should be stopped, but is killed instead.
|
|
|
|
The <STRONG>SIGKILL</STRONG> signal cannot be caught or ignored. The <STRONG>SIGILL</STRONG> and <STRONG>SIGTRAP</STRONG>
|
|
signals cannot be automatically reset. The system silently enforces
|
|
these restrictions. This may or may not be reflected by the attributes
|
|
of these signals and the signal masks.
|
|
|
|
<STRONG>Types</STRONG>
|
|
POSIX prescribes that <sys/types.h> has the following definition:
|
|
|
|
<STRONG>typedef</STRONG> <STRONG>int</STRONG> <STRONG>(*sighandler_t)(int)</STRONG>
|
|
|
|
With this type the following declarations can be made:
|
|
|
|
<STRONG>sighandler_t</STRONG> <STRONG>sa_handler;</STRONG>
|
|
<STRONG>sighandler_t</STRONG> <STRONG>signal(int</STRONG> <EM>sig</EM><STRONG>,</STRONG> <STRONG>sighandler_t</STRONG> <EM>handler</EM><STRONG>);</STRONG>
|
|
|
|
This may help you to understand the earlier declarations better. The
|
|
<STRONG>sighandler_t</STRONG> type is also very useful in old style C code that is
|
|
compiled by a compiler for standard C.
|
|
|
|
|
|
</PRE>
|
|
<H2>SEE ALSO</H2><PRE>
|
|
<STRONG><A HREF="../man1/kill.1.html">kill(1)</A></STRONG>, <STRONG><A HREF="../man2/kill.2.html">kill(2)</A></STRONG>, <STRONG><A HREF="../man2/pause.2.html">pause(2)</A></STRONG>, <STRONG><A HREF="../man2/sigprocmask.2.html">sigprocmask(2)</A></STRONG>, <STRONG><A HREF="../man2/sigsuspend.2.html">sigsuspend(2)</A></STRONG>, <STRONG><A HREF="../man2/sigpending.2.html">sigpending(2)</A></STRONG>,
|
|
<STRONG><A HREF="../man3/sigset.3.html">sigset(3)</A></STRONG>.
|
|
|
|
|
|
</PRE>
|
|
<H2>DIAGNOSTICS</H2><PRE>
|
|
<STRONG>Sigaction()</STRONG> returns <STRONG>0</STRONG> on success or <STRONG>-1</STRONG> on error. <STRONG>Signal()</STRONG> returns the
|
|
old handler on success or <STRONG>SIG_ERR</STRONG> on error. The error code may be:
|
|
|
|
<STRONG>EINVAL</STRONG> Bad signal number.
|
|
|
|
<STRONG>EFAULT</STRONG> Bad <EM>act</EM> or <EM>oact</EM> addresses.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</PRE>
|
|
<H2>AUTHOR</H2><PRE>
|
|
Kees J. Bot (kjb@cs.vu.nl)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</PRE>
|
|
</BODY>
|
|
</HTML>
|