Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ sigaction(2) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

acct

exit, _exit

kill, kill3, killpg

pause

ptrace

setjmp, longjmp, _setjmp, _longjmp

sigprocmask, sigsetmask, sigblock

sigemptyset, sigfillset, sigaddset, sigdelset, sigismember

sigstack

sigsuspend, sigpause

umask

wait, waitpid

core

kill



SIGACTION(2,L)              AIX Technical Reference              SIGACTION(2,L)



-------------------------------------------------------------------------------
sigaction, sigvec, signal



PURPOSE

Specifies the action to take upon delivery of a signal.

SYNTAX

#include <signal.h>


int sigaction  (sig, act, oact)
int sig;
struct sigaction *act, *oact;

DESCRIPTION

The sigaction system call allows the calling process to examine and change the
action to be taken when a specific signal is delivered to the process.

The sig parameter specifies the signal.  If the act parameter is not NULL, it
points to a sigaction structure that describes the action to be taken on
receipt of the sig signal.  If the oact parameter is not NULL, it points to a
sigaction structure in which the signal action data in effect at the time of
the sigaction call is returned.  If the act parameter is NULL, signal handling
is unchanged.  Thus, the call can be used to inquire about the current handling
of a given signal.

The sigaction structure has the following members:

      void  (*sa_handler)();
      sigset_t  sa_mask;
      int       sa_flags;

The sa_handler field may have the value SIG_DFL, SIG_IGN, or may be a pointer
to a function.  A value of SIG_DFL requests default action to be taken when the
signal is delivered.  A value of SIG_IGN requests that the signal have no
effect on the receiving process.  A pointer to a function requests that the
signal be caught (that is, the signal should cause the function to be called).
These actions are more fully described below.

The sa_mask field can be used to specify that individual signals, in addition
to those in the process's signal mask, are blocked from being delivered while
the signal handler function specified in sa_handler is executing.  See
"sigemptyset, sigfillset, sigaddset, sigdelset, sigismember" for an explanation
of the use of the sa_mask field.  The sa_flags field may have the bits
SA_RESTART, SA_ONSTACK, SA_OLDSTYLE, or SA_NOCLDSTOP set to specify further
control over the actions taken upon delivery of a signal.




Processed November 7, 1990      SIGACTION(2,L)                                1





SIGACTION(2,L)              AIX Technical Reference              SIGACTION(2,L)



If the SA_ONSTACK bit is set, the system runs the signal-catching function on
the signal stack specified by the sigstack system call.  If this bit is not
set, then the function executes on the stack of the process to which the signal
is delivered.

If the SA_OLDSTYLE bit is set, the signal action is set to SIG_DFL (except for
SIGILL, SIGTRAP, and SIGPWR) prior to calling the signal-catching function.
This is supported for compatibility with old applications, and is not
recommended since the same signal could reoccur before the signal-catching
routine was able to reset the signal action.  The default action (normally
termination) would be taken in that case.

If a signal for which a signal-catching function exists is sent to a process
while that process is executing certain system calls, the call terminates
prematurely with a -1 return code and an errno value of EINTR.  If the
SA_RESTART bit is set in the sa_flags field of the handler for the signal, the
system call does not fail but is restarted automatically.  The affected system
calls are read and write on a slow device (such as a terminal but not a regular
file) and the wait system call.

The sig parameter can be any one of the following signal values except SIGKILL.
Each of the names shown below is defined in the signal.h header file with the
value of the corresponding signal number.

+-----------+------+----------------------------------------------------------+
|SIGHUP     |  1   | Hangup                                                   |
+-----------+------+----------------------------------------------------------+
|SIGINT     |  2   | Interrupt                                                |
+-----------+------+----------------------------------------------------------+
|SIGQUIT    |  3*  | Quit                                                     |
+-----------+------+----------------------------------------------------------+
|SIGILL     |  4*  | Illegal instruction                                      |
+-----------+------+----------------------------------------------------------+
|SIGTRAP    |  5*  | Trace trap                                               |
+-----------+------+----------------------------------------------------------+
|SIGABRT    |  6*  | Abort process (see "abort")                              |
+-----------+------+----------------------------------------------------------+
|SIGEMT     |  7*  | EMT instruction                                          |
+-----------+------+----------------------------------------------------------+
|SIGFPE     |  8*  | Floating-point exception                                 |
+-----------+------+----------------------------------------------------------+
|SIGKILL    |  9   | Kill (may not be caught, blocked, or ignored)            |
+-----------+------+----------------------------------------------------------+
|SIGBUS     | 10*  | Bus error                                                |
+-----------+------+----------------------------------------------------------+
|SIGSEGV    | 11*  | Segmentation violation                                   |
+-----------+------+----------------------------------------------------------+
|SIGSYS     | 12*  | Bad parameter to system call                             |
+-----------+------+----------------------------------------------------------+
|SIGPIPE    | 13   | Write on a pipe with no one to read it                   |
+-----------+------+----------------------------------------------------------+




Processed November 7, 1990      SIGACTION(2,L)                                2





SIGACTION(2,L)              AIX Technical Reference              SIGACTION(2,L)



+-----------+------+----------------------------------------------------------+
|SIGALRM    | 14   | Alarm clock                                              |
+-----------+------+----------------------------------------------------------+
|SIGTERM    | 15   | Software termination signal                              |
+-----------+------+----------------------------------------------------------+
|SIGURG     | 16+  | Urgent condition on I/O channel                          |
+-----------+------+----------------------------------------------------------+
|SIGSTOP    | 17@  | Stop (may not be caught, blocked, or ignored)            |
+-----------+------+----------------------------------------------------------+
|SIGTSTP    | 18@  | Interactive stop signal from TTY                         |
+-----------+------+----------------------------------------------------------+
|SIGCONT    | 19!  | Continue if stopped                                      |
+-----------+------+----------------------------------------------------------+
|SIGCHLD    | 20+  | A child has stopped or exited                            |
+-----------+------+----------------------------------------------------------+
|SIGTTIN    | 21@  | Read of control TTY attempted from background            |
+-----------+------+----------------------------------------------------------+
|SIGTTOU    | 22@  | Write to control TTY attempted from background           |
+-----------+------+----------------------------------------------------------+
|SIGIO      | 23+  | Input/Output possible or complete                        |
+-----------+------+----------------------------------------------------------+
|SIGXCPU    | 24   | CPU time limit exceeded (see setrlimit)                  |
+-----------+------+----------------------------------------------------------+
|SIGXFSZ    | 25   | File size limit exceeded (Not sent by write in AIX)      |
+-----------+------+----------------------------------------------------------+
|reserved   | 26   |                                                          |
+-----------+------+----------------------------------------------------------+
|SIGMSG     | 27#  | HFT input data pending                                   |
+-----------+------+----------------------------------------------------------+
|SIGWINCH   | 28+  | Window size change                                       |
+-----------+------+----------------------------------------------------------+
|SIGPWR     | 29+  | Power failure imminent (save your data)                  |
+-----------+------+----------------------------------------------------------+
|SIGUSR1    | 30   | User-defined signal 1                                    |
+-----------+------+----------------------------------------------------------+
|SIGUSR2    | 31   | User-defined signal 2                                    |
+-----------+------+----------------------------------------------------------+
|SIGPROF    | 32   | Profiling time alarm (see setitimer, "getitimer,         |
|           |      | setitimer")                                              |
+-----------+------+----------------------------------------------------------+
|SIGDANGER  | 33%+ | System crash imminent                                    |
+-----------+------+----------------------------------------------------------+
|SIGVTALRM  | 34   | Virtual time alarm (see setitimer, "getitimer,           |
|           |      | setitimer")                                              |
+-----------+------+----------------------------------------------------------+
|SIGMIGRATE | 35$  | Migrate the process to another CPU                       |
+-----------+------+----------------------------------------------------------+
|SIGPRE     | 36*  | Programming exception.  On the PS/2, this is generated   |
|           |      | by the failure of the test performed by the 80386 BOUND  |
|           |      | instruction.                                             |
+-----------+------+----------------------------------------------------------+




Processed November 7, 1990      SIGACTION(2,L)                                3





SIGACTION(2,L)              AIX Technical Reference              SIGACTION(2,L)



+-----------+------+----------------------------------------------------------+
|reserved   | 37-59|                                                          |
+-----------+------+----------------------------------------------------------+
|SIGGRANT   | 60#  | HFT monitor mode granted                                 |
+-----------+------+----------------------------------------------------------+
|SIGRETRACT | 61#  | HFT monitor mode retracted                               |
+-----------+------+----------------------------------------------------------+
|SIGSOUND   | 62#  | HFT sound sequence has completed                         |
+-----------+------+----------------------------------------------------------+
|reserved   | 63   |                                                          |
+-----------+------+----------------------------------------------------------+

The symbols in the preceding table have the following meaning:

*   Default action includes creating a core dump file.

@   Default action is to stop the process.

!   Default action is to restart or continue the process.

+   Default action is to ignore these signals.

$   Default action is to migrate the process to another CPU.

%   The cause is a shortage of paging space.  See the gpgscln and killem
    stanzas in "master."

#   For more information on the use of these signals, see "hft."

The three types of actions that can be associated with a signal:  SIG_DFL,
SIG_IGN, or a pointer to a function are described as follows:

SIG_DFL - Default action:  Signal-specific default action

    Except for those signal numbers marked with a +, @, $, or !, the default
    action for a signal is to terminate the receiving process with all of the
    consequences described in the _exit system call.  In addition, a memory
    image file will be created in the current directory of the receiving
    process if sig is one for which an asterisk appears in the preceding list
    and the following conditions are met:

      o The effective user ID and the real user ID of the receiving process are
        equal.

      o An ordinary file named core exists in the current directory and is
        writable, or it can be created.  If the file must be created, it will
        have the following properties:

          - The access permission code 0666 (0x1B6), modified by the file
            creation mask (see "umask")





Processed November 7, 1990      SIGACTION(2,L)                                4





SIGACTION(2,L)              AIX Technical Reference              SIGACTION(2,L)



          - 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.

    For signal numbers marked with a !, the default action is to restart the
    receiving process if it is stopped, or to continue execution of the
    receiving process.

    For signal numbers marked with a @, the default action is to stop the
    execution of the receiving process temporarily.  When a process stops, a
    SIGCHLD signal is sent to its parent process, unless the parent process has
    set the SA_NOCLDSTOP flag.  While a process is stopped, any additional
    signals that are sent to the process will not be delivered until the
    process is continued.  An exception to this is SIGKILL, which always
    terminates the receiving process.  Another exception is SIGCONT, which
    always causes the receiving process to restart or continue execution even
    if blocked or ignored.  A process whose parent has terminated shall be sent
    a SIGKILL signal if the SIGTSTP, SIGTTIN, or SIGTTOU signals are generated
    for that process.

    For signal numbers marked with a +, the default action is to ignore the
    signal.  In this case, delivery of the signal has no effect on the
    receiving process.

    If a signal action is set to SIG_DFL while the signal is pending, the
    signal remains pending.

SIG_IGN - Ignore signal.

    Delivery of the signal will have no effect on the receiving process.  If a
    signal action is set to SIG_IGN while the signal is pending, the pending
    signal will be discarded.

    An exception to this is the SIGCHLD signal whose SIG_DFL action is to
    ignore the signal.  If SIGCHLD is set to SIG_IGN, it means that the process
    does not want to receive the SIGCHLD signal when one of its child processes
    dies, and does not want to have its wait calls return because a child
    process is dead (just when no more child processes exist, and on stopped
    child processes).

    Note:  The SIGKILL and SIGSTOP signals cannot be ignored.

pointer to a function - Catch signal.

    Upon delivery of the signal, the receiving process is to execute the
    signal-catching function specified by the pointer to function.  The
    signal-handler subroutine can be declared as follows:






Processed November 7, 1990      SIGACTION(2,L)                                5





SIGACTION(2,L)              AIX Technical Reference              SIGACTION(2,L)



        handler (sig, code, scp)
        int sig, code;
        struct sigcontext *scp;

    The sig parameter is the signal number.  The code parameter gives extra
    information about the cause of certain signals.  For SIGFPE, code specifies
    the nature of the floating-point exception.  For SIGMIGRATE, code is the
    number of the site to which the process should migrate.  For other signals,
    code is always 0.  The scp parameter points to the sigcontext structure
    that is later used to restore the process's previous execution context.
    The sigcontext structure is defined in signal.h.

    A new signal mask is calculated and installed for the duration of the
    signal-catching function (or until sigprocmask or sigsuspend system calls
    are made).  This mask is formed by taking the union of the process's signal
    mask, the mask associated with the action for the signal being delivered,
    and a mask corresponding to the signal being delivered.  The mask
    associated with the signal-catching function is not allowed to block those
    signals that cannot be ignored.  This is enforced by the kernel without
    causing an error to be indicated.  If and when the signal-catching function
    returns, the original signal mask is restored (modified by any sigprocmask
    calls that were made since the signal-catching function was called) and the
    receiving process resumes execution at the point it was interrupted.

    The signal-catching function can cause the process to resume in a different
    context by calling the longjmp subroutine.  When the longjmp subroutine is
    called, the process's signal mask and signal stack state (stack pointer and
    on-signal-stack state) are restored to those in effect at the time the
    corresponding setjmp call was made.

    Once an action is installed for a specific signal, it remains installed
    until another action is explicitly requested (by another call to the
    sigaction system call), or until one of the exec functions is called.  An
    exception to this is when the SA_OLDSTYLE is set in which case the action
    of a caught signal gets set to SIG_DFL, except for SIGILL, SIGTRAP, and
    SIGPWR, prior to calling the signal-catching function for that signal.

    If a signal action is set to a pointer to a function while the signal is
    pending, the signal will remain pending.

    When signal-catching functions are invoked asynchronously with process
    execution, the behavior of some of the functions defined by this reference
    is unspecified if they are called from a signal-catching function.  The
    following table defines a set of functions that shall be reentrant with
    respect to signals (that is, applications may invoke them, without
    restriction, from signal-catching functions):  _exit, access, alarm, chdir,
    chmod, chown, close, creat, dup2, dup, exec, fcntl, fork, fstat, getegid,
    geteuid, getgid, getgroups, getpgrp, getpid, getppid, getuid, kill, link,
    lseek, mkdir, mkfifo, open, pause, pipe, read, rename, rmdir, setgid,
    setpgrp, setuid, sigaction, sigaddset, sigdelset, sigfillset, sigemptyset,
    sigismember, signal, sigpending, sigprocmask, sigsuspend, sleep, stat,
    time, times, umask, uname, unlink, ustat, utime, wait3, wait, write.  No



Processed November 7, 1990      SIGACTION(2,L)                                6





SIGACTION(2,L)              AIX Technical Reference              SIGACTION(2,L)



    other library functions should be called from signal-catching functions,
    since their behavior is undefined.

    Note:  The SIGKILL and SIGSTOP signals cannot be caught.

COMPATIBILITY INTERFACES

#include <sys/signal.h>

int sigvec (sig, invec, outvec)
int sig;
struct sigvec *invec, *outvec;

The sigvec function is the same as a sigaction system call except that the
sigvec structure is used instead of the sigaction structure.  The sigvec
structure specifies a mask as an int instead of a sigset_t.  The mask for
sigvec is constructed by setting the i-th bit in the mask if signal i is to be
blocked.  Therefore, sigvec only allows signals of value 1-32 to be blocked
when a signal-handling function is called.  The other signals will not be
blocked by the signal-handler mask.

Note:  The SA_RESTART flag cannot be specified with sigvec.  Instead, for
       4.3BSD compatibility, the flag SV_INTERRUPT can be specified.
       SV_INTERRUPT has the opposite effect of SA_RESTART.

#include <sys/signal.h> or <signal.h>

void (*signal (sig, action)) ( )
int sig;
void (*action) ( );

The signal function allows the action associated with a signal.  The action
parameter can have the same values that are described for the sa_handler field
in the act structure of the sigaction system call.  However, no signal handler
mask or flags can be specified; the signal function implicitly sets the signal
handler mask to not block the signal sig and the flags to be SA_OLDSTYLE.
Also, a call to the function signal cancels a pending signal sig, except for a
pending SIGKILL.

Upon successful completion of a signal call, the value of the previous signal
action is returned.  If the call fails, a value of SIG_ERR is returned and
errno is set to indicate the error as in the sigaction call.

Note that sigvec and signal do not check for valid pointers, and therefore will
not generate EFAULT.

RETURN VALUE

Upon successful completion, a value of 0 is returned.  If the sigaction system
call fails, a value of -1 is returned and errno is set to indicate the error.





Processed November 7, 1990      SIGACTION(2,L)                                7





SIGACTION(2,L)              AIX Technical Reference              SIGACTION(2,L)



ERROR CONDITIONS

The sigaction system call fails and no new signal handler is installed if one
of the following occurs:

EFAULT    The act or oact parameter points to a location outside of the
          process's allocated address space.

EINVAL    The sig parameter is not a valid signal number.

EINVAL    An attempt was made to ignore or supply a handler for SIGKILL, or
          SIGSTOP.

RELATED INFORMATION

In this book:  "acct," "exit, _exit," "kill, kill3, killpg," "pause," "ptrace,"
"setjmp, longjmp, _setjmp, _longjmp," "sigprocmask, sigsetmask, sigblock,"
"sigemptyset, sigfillset, sigaddset, sigdelset, sigismember," "sigstack,"
"sigsuspend, sigpause," "umask," "wait, waitpid," and "core."

The kill command in AIX Operating System Commands Reference.


































Processed November 7, 1990      SIGACTION(2,L)                                8



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026