sigaction() - Unix, Linux System Call

Unix - Home
Unix - Getting Started
Unix - File Management
Unix - Directories
Unix - File Permission
Unix - Environment
Unix - Basic Utilities
Unix - Pipes & Filters
Unix - Processes
Unix - Communication
Unix - The vi Editor
Unix - What is Shell?
Unix - Using Variables
Unix - Special Variables
Unix - Using Arrays
Unix - Basic Operators
Unix - Decision Making
Unix - Shell Loops
Unix - Loop Control
Unix - Shell Substitutions
Unix - Quoting Mechanisms
Unix - IO Redirections
Unix - Shell Functions
Unix - Manpage Help
Unix - Regular Expressions
Unix - File System Basics
Unix - User Administration
Unix - System Performance
Unix - System Logging
Unix - Signals and Traps
Unix - Useful Commands
Unix - Quick Guide
Unix - Builtin Functions
Unix - System Calls
Unix - Commands List
Unix Useful Resources
Computer Glossary
Who is Who
Copyright © 2014 by tutorialspoint

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

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 (*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, or a pointer to a signal handling function.
This function receives the signal number as its only argument.


If
SA_SIGINFO is specified in
sa_flags, then
sa_sigaction (instead of
sa_handler) specifies the signal-handling function for
signum. This function receives the signal number as its first argument, a
pointer to a
siginfo_t as its second argument and a pointer to a
ucontext_t (cast to void *) as its third argument.


sa_mask gives a mask of signals which should be blocked during execution of
the signal handler.  In addition, the signal which triggered the handler
will be blocked, unless the
SA_NODEFER flag is used.


sa_flags specifies a set of flags which modify the behaviour of the signal handling
process. It is formed by the bitwise OR of zero or more of the following:


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 */
    clock_t  si_utime;  /* User time consumed */
    clock_t  si_stime;  /* System time consumed */
    sigval_t si_value;  /* Signal value */
    int      si_int;    /* POSIX.1b signal */
    void *   si_ptr;    /* POSIX.1b signal */
    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.
(si_signo is unused on Linux.)
The rest of the struct may be a union, so that one should only
read the fields that are meaningful for the given signal.
POSIX.1b signals and
SIGCHLD fill in
si_pid and si_uid.  SIGCHLD also fills in
si_status, 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
si_addr with the address of the fault.
SIGPOLL fills in
si_band and si_fd. 

si_code indicates why this signal was sent.  It is a value, not a bitmask.  The
values which are possible for any signal are listed in this table:


















According to POSIX, the behaviour of a process is undefined after it
ignores a
SIGFPE, SIGILL, or
SIGSEGV signal that was not generated by
kill() or
raise(). 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
SIG_IGN. 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 behaviours 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 perform a
wait(2)
or similar.


POSIX.1-1990 only specified
SA_NOCLDSTOP. POSIX.1-2001 added
SA_NOCLDWAIT, SA_RESETHAND, SA_NODEFER, and
SA_SIGINFO. Use of these latter values in
sa_flags may be less portable in applications intended for older
Unix implementations.


Support for
SA_SIGINFO was added in Linux 2.2.


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 implementation
allowed the receipt of any signal, not just the one we are installing
(effectively overriding any
sa_mask settings).


sigaction() can be called with a null second argument to query the current signal
handler. It can also be used to check whether a given signal 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
sa_mask). Attempts to do so are silently ignored.


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

kill (1)
kill (1)
kill (2)
kill (2)
pause (2)
pause (2)
sigaltstack (2)
sigaltstack (2)
signal (2)
signal (2)
sigpending (2)
sigpending (2)
sigprocmask (2)
sigprocmask (2)
sigqueue (2)
sigqueue (2)
sigsuspend (2)
sigsuspend (2)
wait (2)
wait (2)

Advertisements


    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page