Handling signals using z/OS UNIX with POSIX(ON)

z/OS® UNIX signal processing allows flags to control the behavior of signal processing. Using these flags, you can simulate these signals and a wide variety of other signals such as ANSI, POSIX.1, and BSD.

ANSI C has the following standard signal delivery rules:
  • Traditionally, signal actions are established only through the signal().
  • During signal delivery, the signal action is reset to SIG_DFL before the user signal action catcher function receives control.
  • During signal delivery to a user signal catcher function, the signal mask is not changed.
POSIX.1 has the following standard signal delivery rules:
  • Signal actions are typically established through the sigaction() function. With the addition of XPG4 support, there are a number of new flags that have been defined for sigaction() that extend its flexibility.
  • During signal delivery, the signal action is not changed.
  • During signal delivery to a user signal catcher function, the signal mask is changed to the union of:
    • The signal mask at the time of the interruption
    • A signal mask that blocks the signal type being delivered

    The signal mask is restored when the signal catcher function returns.

BSD signals for the most part are consistent with the POSIX rules above except for the following:
  • BSD signal mask is a 31-bit mask whereas the z/OS UNIX signal mask is a AMODE 64 mask. The relationship of the bits to specific signals is not the same. Therefore, we recommend you change to use the sigset manipulation functions, such as, sigadd(), sigdelete(), sigempty().
  • Traditionally, for BSD to generate a signal action, the signal() function was used. However, because the signal() function is used in ANSI, BSD applications should be changed to use the bsd_signal() function.
  • During signal delivery, the signal action is not changed.
  • During signal delivery to a user signal catcher function, the signal mask is changed to the union of:
    • The signal mask at the time of the interruption
    • The signal mask specified in the sa_mask field of the sigaction() function

    The signal mask is restored once the signal catcher function returns.

For compatibility, z/OS XL C/C++ supports the three standards listed above, and additional functions provided by XPG4.

Under z/OS XL C/C++, the primary function for establishing signal action is the sigaction() function. However, there are a number of other functions that you can use to effect signal processing. All signal types are accessible regardless of the function used to establish the signal action.

Table 1 includes functions that will establish a signal handler for a signal action.

Table 1. Functions that establish a signal handler
BSD Function Purpose
bsd_signal() BSD version of signal()
sigaction() Examine and/or change a signal action
sigignore() Set disposition to ignore a signal
sigset() Change a signal action and/or a thread's signal mask
signal() Specify signal handling

Table 2 lists other signal-related functions.

Table 2. Other signal-related functions
Signal Related Functions Purpose
abort() Stop a program
kill() Send a signal to a process
pthread_kill() Send a signal to a thread
raise() Send a signal to yourself
sigaddset() Add a signal to a signal set
sigdelset() Delete a signal from a signal set
sigemptyset() Initialize a signal set to exclude all signals
sigfillset() Initialize a signal set to include all signals
sighold() Add a signal to a thread's signal mask
siginterrupt() Allow signals to interrupt functions
sigismember() Test if a signal is in a signal set
sigpause() Unblock a signal and wait for a signal
sigprocmask() Examine and/or change a thread's signal mask
sigqueue() Queue a signal to a process
sigrelse() Remove a signal from a thread's signal mask
sigstack() Set and/or get signal stack context
sigaltstack() Set and/or get signal alternate stack context
sigsuspend() Change mask and suspend the thread
sigwait() Wait for asynchronous signal
sigpending() Examine pending signals
sigtimedwait() Wait for queued signals
sigwaitinfo() Wait for queued signals