Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both | POSIX(ON) |
#define _POSIX_SOURCE
#include <signal.h>
int sigaction(int sig, const struct sigaction *__restrict__ new,
struct sigaction *__restrict__ old);
Examines and changes the action associated with a specific signal.
int sig is the number of a recognized signal. sigaction() examines and sets the action to be associated with this signal. See Table 1 for the values of sig, as well as the signals supported by z/OS® UNIX services. The sig argument must be one of the macros defined in the signal.h header file.
const struct sigaction *new may be a NULL pointer. If so, sigaction() merely determines the action currently defined to handle sig. It does not change this action. If new is not NULL, it should point to a sigaction structure. The action specified in this structure becomes the new action associated with sig.
struct sigaction *old points to a memory location where sigaction() can store a sigaction structure. sigaction() uses this memory location to store a sigaction structure describing the action currently associated with sig. old can also be a NULL pointer, in which case sigaction() does not store this information.
This function is supported only in a POSIX program.
Value | Default Action | Meaning |
---|---|---|
SIGABND | 1 | Abend. |
SIGABRT | 1 | Abnormal termination (sent by abort()). |
SIGALRM | 1 | A timeout signal (sent by alarm()). |
SIGBUS | 1 | Bus error (available only when running on MVS™ 5.2 or higher). |
SIGFPE | 1 | Arithmetic exceptions that are not masked, for example, overflow, division by zero, and incorrect operation. |
SIGHUP | 1 | A controlling terminal is suspended, or the controlling process ended. |
SIGILL | 1 | Detection of an incorrect function image. |
SIGINT | 1 | Interactive attention. |
SIGKILL | 1 | A termination signal that cannot be caught or ignored. |
SIGPIPE | 1 | A write to a pipe that is not being read. |
SIGPOLL | 1 | Pollable event occurred (available only when running on MVS 5.2 or higher). |
SIGPROF | 1 | Profiling timer expired (available only when running on MVS 5.2 or higher). |
SIGQUIT | 1 | A quit signal for a terminal. |
SIGSEGV | 1 | Incorrect access to memory. |
SIGSYS | 1 | Bad system call issued (available only when running on MVS 5.2 or higher). |
SIGTERM | 1 | Termination request sent to the program. |
SIGTRAP | 1 | Internal for use by dbx or ptrace. |
SIGURG | 2 | High bandwidth data is available at a socket (available only when running on MVS 5.2 or higher). |
SIGUSR1 | 1 | Intended for use by user applications. |
SIGUSR2 | 1 | Intended for use by user applications. |
SIGVTALRM | 1 | Virtual timer has expired (available only when running on MVS 5.2 or higher). |
SIGXCPU | 1 | CPU time limit exceeded (available only when running on MVS 5.2 or higher). If a process runs out of CPU time and SIGXCPU is caught or ignored, a SIGKILL is generated. |
SIGXFSZ | 1 | File size limit exceeded. |
SIGCHLD | 2 | An ended or stopped child process (SIGCLD is an alias name for this signal). |
SIGIO | 2 | Completion of input or output. |
SIGIOERR | 2 | A serious I/O error was detected. |
SIGWINCH | 2 | Window size has changed (available only when running on MVS 5.2 or higher). |
SIGSTOP | 3 | A stop signal that cannot be caught or ignored. |
SIGTSTP | 3 | A stop signal for a terminal. |
SIGTTIN | 3 | A background process attempted to read from a controlling terminal. |
SIGTTOU | 3 | A background process attempted to write to a controlling terminal. |
SIGCONT | 4 | If stopped, continue. |
If the main program abends in a way that is not caught or handled by the operating system or application, z/OS UNIX terminates the running application with a KILL -9. If z/OS UNIX gets control in EOT or EOM and the terminating status has not been set, z/OS UNIX sets it to appear as if a KILL -9 occurred.
If a signal catcher for a SIGABND, SIGFPE, SIGILL or SIGSEGV signal runs as a result of a program check or an ABEND, and the signal catcher executes a RETURN statement, the process will be terminated.
struct sigaction {
void (*sa_handler)(int);
sigset_t sa_mask;
int sa_flags;
void (*sa_sigaction)(int, siginfo_t *, void *);
};
Special behavior for XPG4.2: This member and sa_sigaction are mutually exclusive of each other. When the SA_SIGINFO flag is set in sa_flags then sa_sigaction is used. Otherwise, sa_handler is used.
sa_mask must be set by using one or more of the signal set manipulation functions: sigemptyset(), sigfillset(), sigaddset(), or sigdelset()
In addition, if this flag is set, sigaction() behaves as if the SA_NODEFER flag were also set.
accept() | fstatvfs() | recvmsg() |
catclose() | fsync() | select() |
catgets() | ftruncate() | semop() |
chmod() | getgrgid() | send() |
chown() | getgrnam() | sendmsg() |
close() | getmsg() | sendto() |
closedir() | getpass() | statvfs() |
connect() | getpwnam() | tcdrain() |
creat() | getpwuid() | tcflow() |
dup2() | ioctl() | tcflush() |
endgrent() | lchown() | tcgetattr() |
fchmod() | lockf() | tcgetpgrp() |
fchown() | mkfifo() | tcsendbreak() |
fclose() | msgrcv() | tcsetattr() |
fcntl() | msgxrcv() | tcsetpgrp() |
fflush() | msgsnd() | tmpfile() |
fgetc() | open() | umount() |
fgetwc() | poll() | wait() |
fopen() | putmsg() | waitid() |
fputc() | read() | waitpid() |
fputwc() | readv() | write() |
freopen() | recv() | |
fseek() | recvfrom() |
void function(int signo);
Where signo is the only argument to the signal handler and it specifies the type of signal that has caused the signal handler function to be invoked.void function(int signo, siginfo_t *info, void *context);
Where two additional arguments are passed to the signal handler function. If the second argument is not a NULL pointer, it will point to an object of type siginfo_t which provides additional information about the source of the signal. A siginfo_t object is a structure contains the following members:If si_signo contains SIGPOLL then si_code can be set to SI_ASYNCIO. Otherwise, if the value of si_code is less than or equal to zero then the signal was generated by another process and the si_pid and si_uid members respectively indicate the process ID and the real user ID of the sender of this signal.
If the value of si_code is less than or equal to zero, then the signal was generated by another process and the si_pid and si_uid members respectively indicate the process ID and the real user ID of the sender of this signal.
When a signal handler installed by sigaction(), with the _SA_OLD_STYLE flag set off, catches a signal, the system calculates a new signal mask by taking the union of the current signal mask, the signals specified by sa_mask, and the signal that was just caught (if the SA_NODEFER flag is not set). This new mask stays in effect until the signal handler returns, or sigprocmask(), sigsuspend(), siglongjmp(), sighold(), sigpause(), or sigrelse() is called. When the signal handler ends, the original signal mask is restored.
After an action has been specified for a particular signal, using sigaction() or signal(), it remains installed until it is explicitly changed with another call to sigaction(), signal(), one of the exec functions, bsd_signal(), sigignore(), sigset(), or until the SA_RESETHAND flag causes it to be reset to SIG_DFL.
After an action has been specified for a particular signal, using sigaction() with the _SA_OLD_STYLE flag not set, it remains installed until it is explicitly changed with another call to sigaction(), signal(), or one of the exec functions.
After an action has been specified for a particular signal, using sigaction() with the _SA_OLD_STYLE flag set or using signal(), it remains installed until it is explicitly changed with another call to sigaction(), signal(), or one of the exec functions, or a signal catcher is driven, where it will be reset to SIG_DFL.
Successful setting of signal action to SIG_IGN for a signal that is pending causes the pending signal to be discarded, whether or not it is blocked. This provides the ability to discard signals that are found to be blocked and pending by sigpending().
void function(int signo, siginfo_t *info, void *context);
Where function is the specified signal-catching function, signo is the signal number of the signal being delivered, info points to an object of type siginfo_t associated with the signal being delivered, and context points to an object of type ucontext_t.Considerations for asynchronous signal-catching functions: Some of the functions have been restricted to be serially reusable with respect to asynchronous signals. That is, the library will not allow an asynchronous signal to interrupt the execution of one of these functions until it has completed.
This restriction needs to be taken into consideration when a signal-catching function is invoked asynchronously because it causes the behavior of some of the library functions to become unpredictable.
access() | alarm() | cfgetispeed() |
cfgetospeed() | cfsetispeed() | cfsetospeed() |
chdir() | chmod() | chown() |
close() | creat() | dup() |
dup2() | execle() | execve() |
_exit() | fcntl() | fork() |
fstat() | getegid() | geteuid() |
getgid() | getgroups() | getpgrp() |
getpid() | getppid() | getuid() |
kill() | link() | lseek() |
mkdir() | mkfifo() | open() |
pathconf() | pause() | pipe() |
pthread_cond_broadcast() | pthread_cond_signal() | pthread_mutex_trylock() |
read() | rename() | rmdir() |
setgid() | setpgid() | setsid() |
setuid() | sigaction() | sigaddset() |
sigdelset() | sigemptyset() | sigfillset() |
sigismember() | sigpending() | sigprocmask() |
sigsuspend() | sleep() | stat() |
sysconf() | tcdrain() | tcflow() |
tcflush() | tcgetattr() | tcgetpgrp() |
tcsendbreak() | tcsetattr() | tcsetpgrp() |
time() | times() | umask() |
uname() | unlink() | utime() |
wait() | waitpid() | write() |
The macro versions of getc() and putc() are not reentrant, even though the library versions of these functions are.
The use of the SIGTHSTOP and SIGTHCONT signal is not supported with this function.
If successful, sigaction() returns 0.
The default action for SIGCHILD and SIGIO is for the signal to be ignored. A sigaction() to set the action to SIG_IGN for SIGIO will result in an error, with errno equal to EINVAL.
⁄* CELEBS13
The first part of this example determines whether the SIGCHLD
signal is currently being ignored.
With a NULL pointer for the new argument, the current signal
handler action is not changed.
*⁄
#define _POSIX_SOURCE
#define _XOPEN_SOURCE_EXTENDED 1
#include <stdio.h>
#include <signal.h>
void main(void) {
struct sigaction info;
if (sigaction(SIGCHLD,NULL,&info) != -1)
if (info.sa_handler == SIG_IGN)
printf("SIGCHLD being ignored.\n");
else if (info.sa_handler == SIG_DFL)
printf("SIGCHLD being defaulted.\n");
}
⁄* CELEBS14
This fragment initializes a sigaction structure to specify
mysig as a signal handler and then sets the signal handler
for SIGCHLD.
Information on the previous signal handler for SIGCHLD is
stored in info.
*⁄
#define _XOPEN_SOURCE_EXTENDED 1
#include <signal.h>
#include <stdio.h>
void mysig(int a) { printf("In mysig\n"); }
void main(void) {
struct sigaction info, newhandler;
if (sigaction(SIGCHLD,NULL,&info) != -1)
if (info.sa_handler == SIG_IGN)
printf("SIGCHLD being ignored.\n");
else if(info.sa_handler == SIG_DFL)
printf("SIGCHLD being defaulted.\n");
newhandler.sa_handler = &mysig;
sigemptyset(&(newhandler.sa_mask));
newhandler.sa_flags = 0;
if (sigaction(SIGCHLD,&newhandler,&info) != -1)
printf("New handler set.\n"); }