Manual Pages for Linux CentOS command on man sigaction
MyWebUniversity

Manual Pages for Linux CentOS command on man sigaction

SIGACTION(2) Linux Programmer's Manual SIGACTION(2)

NAME

sigaction - examine and change a signal action SYNOPSIS

#include int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); Feature Test Macro Requirements for glibc (see featuretestmacros(7)): sigaction(): POSIXCSOURCE >= 1 || XOPENSOURCE || POSIXSOURCE siginfot: POSIXCSOURCE >= 199309L DESCRIPTION The sigaction() system call is used to change the action taken by a process on receipt of a specific signal. (See signal(7) for an over‐ view of signals.) signum specifies the signal and can be any valid signal except SIGKILL and SIGSTOP.

If act is non-NULL, the new action for signal signum is installed from

act. If oldact is non-NULL, the previous action is saved in oldact. The sigaction structure is defined as something like: struct sigaction { void (*sahandler)(int); void (*sasigaction)(int, siginfot *, void *); sigsett samask; int saflags; void (*sarestorer)(void); }; On some architectures a union is involved: do not assign to both sahandler and sasigaction. The sarestorer element is obsolete and should not be used. POSIX does not specify a sarestorer element. sahandler specifies the action to be associated with signum and may be SIGDFL for the default action, SIGIGN to ignore this signal, or a pointer to a signal handling function. This function receives the sig‐ nal number as its only argument. If SASIGINFO is specified in saflags, then sasigaction (instead of

sahandler) specifies the signal-handling function for signum. This function receives the signal number as its first argument, a pointer to a siginfot as its second argument and a pointer to a ucontextt (cast to void *) as its third argument. (Commonly, the handler function doesn't make any use of the third argument. See getcontext(3) for fur‐ ther information about ucontextt.) samask specifies a mask of signals which should be blocked (i.e., added to the signal mask of the thread in which the signal handler is invoked) during execution of the signal handler. In addition, the sig‐ nal which triggered the handler will be blocked, unless the SANODEFER flag is used. saflags specifies a set of flags which modify the behavior of the sig‐ nal. It is formed by the bitwise OR of zero or more of the following: SANOCLDSTOP If signum is SIGCHLD, do not receive notification when child processes stop (i.e., when they receive one of SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU) or resume (i.e., they receive SIGCONT) (see wait(2)). This flag is meaningful only when establishing a handler for SIGCHLD. SANOCLDWAIT (since Linux 2.6) If signum is SIGCHLD, do not transform children into zombies when they terminate. See also waitpid(2). This flag is meaningful only when establishing a handler for SIGCHLD, or when setting that signal's disposition to SIGDFL. If the SANOCLDWAIT flag is set when establishing a handler for SIGCHLD, POSIX.1 leaves it unspecified whether a SIGCHLD signal is generated when a child process terminates. On Linux, a SIGCHLD signal is generated in this case; on some other implementations, it is not. SANODEFER Do not prevent the signal from being received from within its own signal handler. This flag is meaningful only when establishing a signal handler. SANOMASK is an obsolete, nonstandard synonym for this flag. SAONSTACK Call the signal handler on an alternate signal stack pro‐ vided by sigaltstack(2). If an alternate stack is not available, the default stack will be used. This flag is meaningful only when establishing a signal handler. SARESETHAND Restore the signal action to the default upon entry to the signal handler. This flag is meaningful only when estab‐ lishing a signal handler. SAONESHOT is an obsolete, non‐ standard synonym for this flag. SARESTART Provide behavior compatible with BSD signal semantics by making certain system calls restartable across signals. This flag is meaningful only when establishing a signal han‐ dler. See signal(7) for a discussion of system call restarting. SASIGINFO (since Linux 2.2) The signal handler takes three arguments, not one. In this case, sasigaction should be set instead of sahandler. This flag is meaningful only when establishing a signal han‐ dler. The siginfot argument to sasigaction is a struct with the following elements: siginfot { int sisigno; /* Signal number */ int sierrno; /* An errno value */ int sicode; /* Signal code */ int sitrapno; /* Trap number that caused

hardware-generated signal (unused on most architectures) */ pidt sipid; /* Sending process ID */ uidt siuid; /* Real user ID of sending process */ int sistatus; /* Exit value or signal */ clockt siutime; /* User time consumed */ clockt sistime; /* System time consumed */ sigvalt sivalue; /* Signal value */ int siint; /* POSIX.1b signal */ void *siptr; /* POSIX.1b signal */ int sioverrun; /* Timer overrun count; POSIX.1b timers */ int sitimerid; /* Timer ID; POSIX.1b timers */ void *siaddr; /* Memory location which caused fault */ long siband; /* Band event (was int in glibc 2.3.2 and earlier) */ int sifd; /* File descriptor */ short siaddrlsb; /* Least significant bit of address (since Linux 2.6.32) */ } sisigno, sierrno and sicode are defined for all signals. (sierrno is generally unused on Linux.) The rest of the struct may be a union, so that one should read only the fields that are meaningful for the given signal: * Signals sent with kill(2) and sigqueue(3) fill in sipid and siuid. In addition, signals sent with sigqueue(3) fill in siint and siptr with the values specified by the sender of the signal; see sigqueue(3) for more details. * Signals sent by POSIX.1b timers (since Linux 2.6) fill in sioverrun and sitimerid. The sitimerid field is an internal ID used by the kernel to identify the timer; it is not the same as the timer ID returned by timercreate(2). The sioverrun field is the timer over‐ run count; this is the same information as is obtained by a call to timergetoverrun(2). These fields are nonstandard Linux extensions. * Signals sent for message queue notification (see the description of SIGEVSIGNAL in mqnotify(3)) fill in siint/siptr, with the sigevvalue supplied to mqnotify(3); sipid, with the process ID of the message sender; and siuid, with the real user ID of the message sender. * SIGCHLD fills in sipid, siuid, sistatus, siutime and sistime, providing information about the child. The sipid field is the process ID of the child; siuid is the child's real user ID. The sistatus field contains the exit status of the child (if sicode is CLDEXITED), or the signal number that caused the process to change state. The siutime and sistime contain the user and system CPU time used by the child process; these fields do not include the times

used by waited-for children (unlike getrusage(2) and time(2)). In kernels up to 2.6, and since 2.6.27, these fields report CPU time in units of sysconf(SCCLKTCK). In 2.6 kernels before 2.6.27, a bug meant that these fields reported time in units of the (configurable) system jiffy (see time(7)). * SIGILL, SIGFPE, SIGSEGV, SIGBUS, and SIGTRAP fill in siaddr with the address of the fault. On some architectures, these signals also fill in the sitrapno filed. Some suberrors of SIGBUS, in particular BUSMCEERRAO and BUSMCEERRAR, also fill in siaddrlsb. This field indicates the least significant bit of the reported address and therefore the extent of the corruption. For example, if a full page was corrupted, siaddrlsb contains log2(sysconf(SCPAGESIZE)).

BUSMCERR* and siaddrlsb are Linux-specific extensions. * SIGIO/SIGPOLL (the two names are synonyms on Linux) fills in siband and sifd. The siband event is a bit mask containing the same val‐ ues as are filled in the revents field by poll(2). The sifd field indicates the file descriptor for which the I/O event occurred. sicode is a value (not a bit mask) indicating why this signal was sent. The following list shows the values which can be placed in sicode for any signal, along with reason that the signal was gener‐ ated. SIUSER kill(2) SIKERNEL Sent by the kernel. SIQUEUE sigqueue(3) SITIMER POSIX timer expired SIMESGQ POSIX message queue state changed (since Linux 2.6.6); see mqnotify(3) SIASYNCIO AIO completed SISIGIO Queued SIGIO (only in kernels up to Linux 2.2; from Linux 2.4 onward SIGIO/SIGPOLL fills in sicode as described below). SITKILL tkill(2) or tgkill(2) (since Linux 2.4.19) The following values can be placed in sicode for a SIGILL signal: ILLILLOPC illegal opcode ILLILLOPN illegal operand ILLILLADR illegal addressing mode ILLILLTRP illegal trap ILLPRVOPC privileged opcode ILLPRVREG privileged register ILLCOPROC coprocessor error ILLBADSTK internal stack error The following values can be placed in sicode for a SIGFPE signal: FPEINTDIV integer divide by zero FPEINTOVF integer overflow

FPEFLTDIV floating-point divide by zero

FPEFLTOVF floating-point overflow

FPEFLTUND floating-point underflow

FPEFLTRES floating-point inexact result

FPEFLTINV floating-point invalid operation FPEFLTSUB subscript out of range The following values can be placed in sicode for a SIGSEGV signal: SEGVMAPERR address not mapped to object SEGVACCERR invalid permissions for mapped object The following values can be placed in sicode for a SIGBUS signal: BUSADRALN invalid address alignment BUSADRERR nonexistent physical address

BUSOBJERR object-specific hardware error BUSMCEERRAR (since Linux 2.6.32) Hardware memory error consumed on a machine check; action required. BUSMCEERRAO (since Linux 2.6.32) Hardware memory error detected in process but not consumed; action optional. The following values can be placed in sicode for a SIGTRAP signal: TRAPBRKPT process breakpoint TRAPTRACE process trace trap TRAPBRANCH (since Linux 2.4) process taken branch trap TRAPHWBKPT (since Linux 2.4) hardware breakpoint/watchpoint The following values can be placed in sicode for a SIGCHLD signal: CLDEXITED child has exited CLDKILLED child was killed CLDDUMPED child terminated abnormally CLDTRAPPED traced child has trapped CLDSTOPPED child has stopped CLDCONTINUED stopped child has continued (since Linux 2.6.9) The following values can be placed in sicode for a SIGIO/SIGPOLL sig‐ nal: POLLIN data input available POLLOUT output buffers available POLLMSG input message available POLLERR I/O error POLLPRI high priority input available POLLHUP device disconnected RETURN VALUE

sigaction() returns 0 on success; on error, -1 is returned, and errno is set to indicate the error. ERRORS EFAULT act or oldact points to memory which is not a valid part of the process address space. EINVAL An invalid signal was specified. This will also be generated if an attempt is made to change the action for SIGKILL or SIGSTOP, which cannot be caught or ignored. CONFORMING TO

POSIX.1-2001, SVr4. NOTES A child created via fork(2) inherits a copy of its parent's signal dis‐ positions. During an execve(2), the dispositions of handled signals are reset to the default; the dispositions of ignored signals are left unchanged. According to POSIX, the behavior of a process is undefined after it ignores a SIGFPE, SIGILL, or SIGSEGV signal that was not generated by kill(2) or raise(3). Integer division by zero has undefined result. On some architectures it will generate a SIGFPE signal. (Also dividing

the most negative integer by -1 may generate SIGFPE.) Ignoring this signal might lead to an endless loop.

POSIX.1-1990 disallowed setting the action for SIGCHLD to SIGIGN.

POSIX.1-2001 allows this possibility, so that ignoring SIGCHLD can be used to prevent the creation of zombies (see wait(2)). Nevertheless, the historical BSD and System V behaviors for ignoring SIGCHLD differ, so that the only completely portable method of ensuring that terminated children do not become zombies is to catch the SIGCHLD signal and per‐ form a wait(2) or similar.

POSIX.1-1990 specified only SANOCLDSTOP. POSIX.1-2001 added SANOCLD‐ WAIT, SARESETHAND, SANODEFER, and SASIGINFO. Use of these latter values in saflags may be less portable in applications intended for older UNIX implementations. The SARESETHAND flag is compatible with the SVr4 flag of the same name. The SANODEFER flag is compatible with the SVr4 flag of the same name under kernels 1.3.9 and newer. On older kernels the Linux implementa‐ tion allowed the receipt of any signal, not just the one we are installing (effectively overriding any samask settings). sigaction() can be called with a NULL second argument to query the cur‐ rent signal handler. It can also be used to check whether a given sig‐ nal is valid for the current machine by calling it with NULL second and third arguments. It is not possible to block SIGKILL or SIGSTOP (by specifying them in samask). Attempts to do so are silently ignored. See sigsetops(3) for details on manipulating signal sets.

See signal(7) for a list of the async-signal-safe functions that can be safely called inside from inside a signal handler. Undocumented Before the introduction of SASIGINFO it was also possible to get some additional information, namely by using a sahandler with second argu‐ ment of type struct sigcontext. See the relevant Linux kernel sources for details. This use is obsolete now. BUGS In kernels up to and including 2.6.13, specifying SANODEFER in saflags prevents not only the delivered signal from being masked dur‐ ing execution of the handler, but also the signals specified in samask. This bug was fixed in kernel 2.6.14. EXAMPLE See mprotect(2). SEE ALSO kill(1), kill(2), killpg(2), pause(2), restartsyscall(2), sigalt‐ stack(2), signal(2), signalfd(2), sigpending(2), sigprocmask(2), sig‐ suspend(2), wait(2), raise(3), siginterrupt(3), sigqueue(3), sigse‐ tops(3), sigvec(3), core(5), signal(7) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

Linux 2013-07-30 SIGACTION(2)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™