Using Signal APIs

Signal Concepts

An X/Open specification defines a "signal" as a mechanism by which a process may be notified of, or affected by, an event occurring in the system. The term signal is also used to refer to the event itself.

A signal is said to be generated when the event that causes the signal first occurs. Examples of such events include the following:

A synchronous signal is a signal that is generated by some action attributable to a program running within the thread, such as a system-detected error, raise(), or CEESGL. An asynchronous signal is a signal that is generated for the process by using the kill() function or by an asynchronous event such as terminal activity or an expired timer.

The signal action vector is a list of signal-handling actions for each defined signal. The signal action vector is maintained separately for each process and is inherited from the parent process. The signal action vector specifies the signal-handling actions for both synchronously and asynchronously generated signals.

A signal is said to be delivered to a process when the specified signal-handling action for the signal is taken. A signal is said to be accepted by a process when a signal is selected and returned by one of the sigwait functions.

Signals generated for a process are delivered to or accepted by one thread in the process.

A signal is said to be pending during the interval between the time the signal is generated and the time it is delivered or accepted. Ordinarily, this interval cannot be detected by an application. However, a signal can be blocked from being delivered to a thread. When a signal is blocked, the signal-handling action associated with the signal is not taken. If there are no threads in a call to a sigwait function selecting the signal and if all threads block delivery of the signal, the signal remains pending on the process. The signal remains pending until either a thread calls a sigwait function selecting the signal, a thread unblocks delivery of the signal, or the signal action associated with the signal is set to ignore the signal. The signal blocking mask defines the set of signals that are blocked from delivery to the thread. The signal blocking mask is maintained separately for each thread in the process and is inherited from the thread that created it.


IBM i Signal Management

The set of defined signals is determined by the system. The system specifies the attributes for each defined signal. These attributes consist of a signal number, the initial signal action, and the signal default action. The system also specifies an initial signal blocking mask. The set of defined signals, the signal attributes, and signal blocking mask are referred to as signal controls.

A signal can be generated or delivered only to a process that has expressed an interest in signals. An error condition results under the following conditions:

A process can express an interest in signals by calling the Qp0sEnableSignals() API. In addition, calling particular signal APIs implicitly enables the process for signals.

If the process has not been enabled for signals, the process signal controls are set from signal controls established by the system during IPL (the system signal controls). An error condition results if an attempt is made to enable signals for the process before the system signal controls have been initialized.

Once the process signal controls have been initialized, the user is permitted to change the signal controls for the process. For example, the signal blocking mask and the signal action for a signal are commonly changed. Some signal controls, such as the number of defined signals and the signal default action for a signal, cannot be changed at the process level.

The attributes for each defined signal are stored in an object called a signal monitor. The system supports a maximum of 63 signal monitors for each process. The process signal action vector is a list of signal monitors, one for each defined signal. The signal monitor contains, but is not limited to, the following information:

The signal action defines the action to be taken by the system when a process receives an unblocked signal. The user can change the signal action for a process signal monitor. The possible signal actions are:

The signal default action field defines the action to be taken by the system when the signal action is set to handle using signal default action. The signal default action for a signal monitor is set in the system signal controls and cannot be changed for a process signal monitor. The possible signal default actions are:

The signal options specify an additional set of attributes for the signal monitor. The primary use of these options is to specify an additional set of actions to be taken by the system when a signal-catching function is called.

A signal is generated by sending a request to a signal monitor. Scheduling of the signal-handling action is controlled separately for each signal monitor through the signal blocking mask. The signal blocking mask is a bit mask that defines the set of signals to be blocked from delivery to the thread. The blocked or unblocked option specified for the nth bit position in the signal blocking mask is applied to the nth signal monitor defined for the process. When signal is unblocked is specified, the signal-handling action is eligible to be scheduled. When signal is blocked is specified, the signal-handling action is blocked from delivery.

The process to receive the signal is identified by a process ID. The process ID is used to indicate whether the signal should be sent to an individual process or to a group of processes (known as a process group). The process ID is a 4-byte binary number that is used to locate an entry in the system-managed process table. A process table entry contains the following information relating to the process:

The parent process is the logical creator of the process. A process group represents a collection of processes that are bound together for some common purpose. An error condition results if the process ID specified when a signal is sent does not represent a valid process or process group.

The process sending a signal must have the appropriate authority to the receiving process. The parent process is allowed to send a signal to a child process (the parent process ID of the receiving process is equal to the process ID of the process sending the signal). A child process is allowed to send a signal to its parent process (the process ID of the receiving process is equal to the parent process ID of the process sending the signal). A process can send a signal to another process if the sending process has *JOBCTL authority defined for the current process user profile or in an adopted user profile. Otherwise, the real or effective user ID of the sending process must match the real or effective user ID of the receiving process. An error condition results if the process does not have authority to send the signal to a receiving process.


Differences from Signals on UNIX Systems

The IBM® i support for signals does differ from the usual behavior of signals on UNIX® systems:


[ Back to top | UNIX-Type APIs | APIs by category ]