Seth Woolley's Man Viewer

sigaction(2) - sigaction, sigpending, sigprocmask, sigsuspend, sigaction, sigpending, sigprocmask, sigsuspend - POSIX signal handling functions - man 2 sigaction

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

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



NAME
       sigaction,  sigprocmask, sigpending, sigsuspend - POSIX signal(2,7) handling
       functions

SYNOPSIS
       #include <signal.h>


       int sigaction(int signum, const struct sigaction *act, struct sigaction
       *oldact);

       int sigprocmask(int how, const sigset_t *set(7,n,1 builtins), sigset_t *oldset);

       int sigpending(sigset_t *set(7,n,1 builtins));

       int sigsuspend(const sigset_t *mask);

DESCRIPTION
       The  sigaction  system  call  is  used  to change the action taken by a
       process on receipt of a specific signal.

       signum specifies the signal(2,7) and can be any valid signal(2,7) except  SIGKILL
       and SIGSTOP.

       If  act is non-null, the new action for signal(2,7) signum is installed from
       act.  If oldact is non-null, the previous action is saved in(1,8) oldact.

       The sigaction structure is defined as something like

              struct sigaction {
                  void (*sa_handler)(int);
                  void (*sa_sigaction)(int, siginfo_t *, void *);
                  sigset_t sa_mask;
                  int sa_flags;
                  void (*sa_restorer)(void);
              }

       On some architectures a union is involved  -  do  not  assign  to  both
       sa_handler and sa_sigaction.

       The sa_restorer element is obsolete and should not be used.  POSIX does
       not specify a sa_restorer element.

       sa_handler specifies the action to be associated with signum and may be
       SIG_DFL  for  the  default  action, SIG_IGN to ignore this signal(2,7), or a
       pointer to a signal(2,7) handling function.  This function receives the sig-
       nal(2,7) number as its only argument.

       sa_sigaction  also  specifies  the action to be associated with signum.
       This function receives the signal(2,7)  number  as  its  first  argument,  a
       pointer  to a siginfo_t as its second argument and a pointer to a ucon-
       text_t (cast to void *) as its third argument.

       sa_mask gives a mask of signals which should be blocked  during  execu-
       tion  of  the  signal(2,7) handler.  In addition, the signal(2,7) which triggered
       the handler will be blocked, unless the SA_NODEFER or  SA_NOMASK  flags
       are used.

       sa_flags  specifies  a  set(7,n,1 builtins)  of flags which modify the behaviour of the
       signal(2,7) handling process. It is formed by the bitwise OR of zero or more
       of the following:

              SA_NOCLDSTOP
                     If  signum  is  SIGCHLD, do not receive notification when
                     child processes stop (i.e., when child processes  receive
                     one of SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU).

              SA_ONESHOT or SA_RESETHAND
                     Restore  the  signal(2,7) action to the default state once the
                     signal(2,7) handler has been called.

              SA_ONSTACK
                     Call the signal(2,7) handler on an alternate signal(2,7) stack pro-
                     vided  by  sigaltstack(2).   If an alternate stack is not
                     available, the default stack will be used.

              SA_RESTART
                     Provide behaviour compatible with BSD signal(2,7) semantics by
                     making certain system calls restartable across signals.

              SA_NOMASK or SA_NODEFER
                     Do not prevent the signal(2,7) from being received from within
                     its own signal(2,7) handler.

              SA_SIGINFO
                     The signal(2,7) handler takes 3 arguments, not one.   In  this
                     case,  sa_sigaction  should be set(7,n,1 builtins) instead of sa_handler.
                     (The sa_sigaction field was added in(1,8) Linux 2.1.86.)

       The siginfo_t parameter to sa_sigaction is a struct with the  following
       elements

              siginfo_t {
                  int      si_signo;  /* Signal number */
                  int      si_errno;  /* An errno value */
                  int      si_code;   /* Signal code */
                  pid_t    si_pid;    /* Sending process ID */
                  uid_t    si_uid;    /* Real user ID of sending process */
                  int      si_status; /* Exit value or signal(2,7) */
                  clock_t  si_utime;  /* User time(1,2,n) consumed */
                  clock_t  si_stime;  /* System time(1,2,n) consumed */
                  sigval_t si_value;  /* Signal value */
                  int      si_int;    /* POSIX.1b signal(2,7) */
                  void *   si_ptr;    /* POSIX.1b signal(2,7) */
                  void *   si_addr;   /* Memory location which caused fault */
                  int      si_band;   /* Band event */
                  int      si_fd;     /* File descriptor */
              }

       si_signo,  si_errno  and si_code are defined for all signals.  The rest
       of the struct may be a union, so that one should only read(2,n,1 builtins)  the  fields
       that  are  meaningful  for the given signal.  kill(1,2,1 builtins)(2), POSIX.1b signals
       and SIGCHLD fill in(1,8) si_pid and si_uid.   SIGCHLD also fills in(1,8)  si_sta-
       tus,  si_utime  and  si_stime.   si_int and si_ptr are specified by the
       sender of the POSIX.1b signal.  SIGILL, SIGFPE, SIGSEGV and SIGBUS fill
       in(1,8) si_addr with the address of the fault.  SIGPOLL fills in(1,8) si_band and
       si_fd.

       si_code indicates why this signal(2,7) was sent.  It is a value, not a  bit-
       mask.   The values which are possible for any signal(2,7) are listed in(1,8) this
       table:

       +------------------------------------+
       |              si_code               |
       +-----------+------------------------+
       |Value      | Signal origin          |
       +-----------+------------------------+
       |SI_USER    | kill(1,2,1 builtins), sigsend or raise(3,n) |
       +-----------+------------------------+
       |SI_KERNEL  | The kernel             |
       +-----------+------------------------+
       |SI_QUEUE   | sigqueue               |
       +-----------+------------------------+
       |SI_TIMER   | timer expired          |
       +-----------+------------------------+
       |SI_MESGQ   | mesq state changed     |
       +-----------+------------------------+
       |SI_ASYNCIO | AIO completed          |
       +-----------+------------------------+
       |SI_SIGIO   | queued SIGIO           |
       +-----------+------------------------+

       +-------------------------------------+
       |               SIGILL                |
       +-----------+-------------------------+
       |ILL_ILLOPC | illegal opcode          |
       +-----------+-------------------------+
       |ILL_ILLOPN | illegal operand         |
       +-----------+-------------------------+
       |ILL_ILLADR | illegal addressing mode |
       +-----------+-------------------------+
       |ILL_ILLTRP | illegal trap            |
       +-----------+-------------------------+
       |ILL_PRVOPC | privileged opcode       |
       +-----------+-------------------------+
       |ILL_PRVREG | privileged register     |
       +-----------+-------------------------+
       |ILL_COPROC | coprocessor error(8,n)       |
       +-----------+-------------------------+
       |ILL_BADSTK | internal stack error(8,n)    |
       +-----------+-------------------------+

       +----------------------------------------------+
       |                   SIGFPE                     |
       +-----------+----------------------------------+
       |FPE_INTDIV | integer divide by zero           |
       +-----------+----------------------------------+
       |FPE_INTOVF | integer overflow                 |
       +-----------+----------------------------------+
       |FPE_FLTDIV | floating point divide by zero    |
       +-----------+----------------------------------+
       |FPE_FLTOVF | floating point overflow          |
       +-----------+----------------------------------+
       |FPE_FLTUND | floating point underflow         |
       +-----------+----------------------------------+
       |FPE_FLTRES | floating point inexact result    |
       +-----------+----------------------------------+
       |FPE_FLTINV | floating point invalid operation |
       +-----------+----------------------------------+
       |FPE_FLTSUB | subscript out of range           |
       +-----------+----------------------------------+

       +----------------------------------------------------+
       |                      SIGSEGV                       |
       +------------+---------------------------------------+
       |SEGV_MAPERR | address not mapped to object          |
       +------------+---------------------------------------+
       |SEGV_ACCERR | invalid permissions for mapped object |
       +------------+---------------------------------------+

       +--------------------------------------------+
       |                  SIGBUS                    |
       +-----------+--------------------------------+
       |BUS_ADRALN | invalid address alignment      |
       +-----------+--------------------------------+
       |BUS_ADRERR | non-existent physical address  |
       +-----------+--------------------------------+
       |BUS_OBJERR | object specific hardware error(8,n) |
       +-----------+--------------------------------+

       +--------------------------------+
       |            SIGTRAP             |
       +-----------+--------------------+
       |TRAP_BRKPT | process breakpoint |
       +-----------+--------------------+
       |TRAP_TRACE | process trace(3x,n,3x _nc_tracebits) trap |
       +-----------+--------------------+

       +--------------------------------------------+
       |                  SIGCHLD                   |
       +--------------+-----------------------------+
       |CLD_EXITED    | child has exited            |
       +--------------+-----------------------------+
       |CLD_KILLED    | child was killed            |
       +--------------+-----------------------------+
       |CLD_DUMPED    | child terminated abnormally |
       +--------------+-----------------------------+
       |CLD_TRAPPED   | traced child has trapped    |
       +--------------+-----------------------------+
       |CLD_STOPPED   | child has stopped           |
       +--------------+-----------------------------+
       |CLD_CONTINUED | stopped child has continued |
       +--------------+-----------------------------+

       +-----------------------------------------+
       |                SIGPOLL                  |
       +---------+-------------------------------+
       |POLL_IN  | data input available          |
       +---------+-------------------------------+
       |POLL_OUT | output buffers available      |
       +---------+-------------------------------+
       |POLL_MSG | input message available       |
       +---------+-------------------------------+
       |POLL_ERR | i/o error(8,n)                     |
       +---------+-------------------------------+
       |POLL_PRI | high priority input available |
       +---------+-------------------------------+
       |POLL_HUP | device disconnected           |
       +---------+-------------------------------+

       The sigprocmask call is used to change the list  of  currently  blocked
       signals. The behaviour of the call is dependent on the value of how, as
       follows.

              SIG_BLOCK
                     The set(7,n,1 builtins) of blocked signals is the union  of  the  current
                     set(7,n,1 builtins) and the set(7,n,1 builtins) argument.

              SIG_UNBLOCK
                     The  signals  in(1,8)  set(7,n,1 builtins) are removed from the current set(7,n,1 builtins) of
                     blocked signals.  It is legal to  attempt  to  unblock  a
                     signal(2,7) which is not blocked.

              SIG_SETMASK
                     The set(7,n,1 builtins) of blocked signals is set(7,n,1 builtins) to the argument set(7,n,1 builtins).

       If  oldset is non-null, the previous value of the signal(2,7) mask is stored
       in(1,8) oldset.

       The sigpending call allows the examination  of  pending  signals  (ones
       which have been raised while blocked).  The signal(2,7) mask of pending sig-
       nals is stored in(1,8) set(7,n,1 builtins).

       The sigsuspend call  temporarily  replaces  the  signal(2,7)  mask  for  the
       process  with  that given by mask and then suspends the process until a
       signal(2,7) is received.


RETURN VALUE
       The functions sigaction, sigprocmask, and sigpending return 0  on  suc-
       cess  and -1 on error.  The function sigsuspend always returns -1, nor-
       mally with the error(8,n) EINTR.


ERRORS
       EFAULT act, oldact, set(7,n,1 builtins), oldset or mask point to memory which is not  a
              valid part of the process address space.

       EINTR  System call was interrupted.

       EINVAL An invalid signal(2,7) was specified.  This will also be generated if(3,n)
              an attempt is made to change the action for SIGKILL or  SIGSTOP,
              which cannot be caught.

NOTES
       It  is  not  possible  to block SIGKILL or SIGSTOP with the sigprocmask
       call.  Attempts to do so will be silently ignored.

       According to POSIX, the behaviour of a process is  undefined  after  it
       ignores  a  SIGFPE, SIGILL, or SIGSEGV signal(2,7) that was not generated by
       the kill(1,2,1 builtins)() or the raise(3,n)() functions.   Integer  division  by  zero  has
       undefined result.  On some architectures it will generate a SIGFPE sig-
       nal.  (Also dividing the most  negative  integer  by  -1  may  generate
       SIGFPE.)  Ignoring this signal(2,7) might lead to an endless loop.

       POSIX  (B.3.3.1.3) disallows setting the action for SIGCHLD to SIG_IGN.
       The BSD and SYSV behaviours differ, causing BSD software that sets  the
       action for SIGCHLD to SIG_IGN to fail on Linux.

       The  POSIX  spec  only  defines SA_NOCLDSTOP.  Use of other sa_flags is
       non-portable.

       The SA_RESETHAND flag is compatible with the  SVr4  flag  of  the  same
       name.

       The  SA_NODEFER  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(2,7),  not  just the one we are
       installing (effectively overriding any sa_mask settings).

       The SA_RESETHAND  and  SA_NODEFER  names  for  SVr4  compatibility  are
       present only in(1,8) library versions 3.0.9 and greater.

       The SA_SIGINFO flag is specified by POSIX.1b.  Support for it was added
       in(1,8) Linux 2.2.

       sigaction can be called with a null second argument to query  the  cur-
       rent  signal(2,7) handler. It can also be used to check whether a given sig-
       nal(2,7) is valid for the current machine by calling it with null second and
       third arguments.

       See sigsetops(3) for details on manipulating signal(2,7) sets.

CONFORMING TO
       POSIX, SVr4.  SVr4 does not document the EINTR condition.


UNDOCUMENTED
       Before  the introduction of SA_SIGINFO it was also possible to get some
       additional information, namely by using a sa_handler with second  argu-
       ment  of  type  struct sigcontext.  See the relevant kernel sources for
       details.  This use is obsolete now.


SEE ALSO
       kill(1,2,1 builtins)(1),  kill(1,2,1 builtins)(2),  killpg(2,3)(2),  pause(2),  sigaltstack(2),   signal(2,7)(2),
       sigvec(2), raise(3,n)(3), siginterrupt(3), sigsetops(3), signal(2,7)(7)



Linux 2.4                         2001-12-29                      SIGACTION(2)

References for this manual (incoming links)