Signal "Pending" and "blocked"

Source: Internet
Author: User

Signal Status:
The "Pending" signal is a state, which refers to the period of time from the generation of the signal to the signal being processed; the "blocking" of the signal is a switching action that refers to blocking the signal from being processed, but not preventing the signal from being generated.
Apue example in sleep before using Sigprocmask block the exit signal, and then sleep, and then in the process of sleep generated an exit signal, but at this time the exit signal is blocked, (Chinese "blocking" here is easily misunderstood as a state, is actually a switch-like action, so said "blocked", rather than "blocked", so in the "pending" state, after sleep and then use Sigprocmask to switch off the exit signal blocking switch, because the previously generated exit signal has been in the pending state, when the blocking switch, immediately exit "Pending" status, get processed, all this happens before Sigprocmask returns.

Signal life cycle:
For a complete signal life cycle (from the signal to the corresponding processing function completed), can be divided into three important stages, these three stages are described by four important events: 1. The birth of a signal; 2. The signal is registered in the process; 3. The signal is written off in the process; 4. The signal processing function is completed. The time interval of two adjacent events constitutes a phase of the signal life cycle.
The following illustrates the practical significance of the four events:
1. The signal "born". The birth of a signal is the occurrence of an event that triggers a signal, such as a hardware exception detected, a timer timeout, and a call to signal sending function kill () or Sigqueue ().

2. The signal is "registered" in the target process;
The TASK_STRUCT structure of the process has data members about the outstanding signals in this process:
struct sigpending pending;
struct sigpending
struct Sigqueue *head, **tail;
sigset_t signal;
The first and second members point to a sigqueue type of structure chain (called the "pending signal information chain") of the end and end, the third member is all the outstanding signal sets in the process, each sigqueue structure in the information chain depicts the information carried by a particular signal, and point to the next Sigqueue structure:
struct Sigqueue
struct Sigqueue *next;
siginfo_t info;
Signal registration in the process refers to the signal value added to the process of the outstanding signal set (sigpending structure of the second member sigset_t Signal), and the information carried by the signal is retained in a sigqueue structure of the outstanding signal information chain. As long as the signal is in the pending signal set of the process, it indicates that the process is aware of the presence of these signals but has not yet been processed, or that the signal is blocked by the process.
When a real-time signal is sent to a process, regardless of whether the signal has been registered in the process, it will be re-registered once, so the signal is not lost, so the real-time signal is also called "reliable signal." This means that the same real-time signal can occupy multiple sigqueue structures in the pending signal information chain of the same process (the process receives a real-time signal, assigns it a structure to register the signal information, and adds the structure to the left of the pending signal chain, i.e. all real-time signals that are born are registered in the target process) ;
When a non-real-time signal is sent to a process, if the signal is already registered in the process, the signal is discarded, causing the signal to be lost. Therefore, the non-real-time signal is also called "unreliable signal". This means that the same non-real-time signal in the process of the pending signal information chain, at most occupy a sigqueue structure (a non-real-time signal is born, (1), if the same signal is found in the target structure is registered, then no longer registered, for the process, the equivalent of not know this signal occurs, signal loss ; (2), if there is no same signal in the pending signal of the process, register itself in the process).

3. Logout of the signal in progress. During the execution of the target process, it detects if there is a signal waiting to be processed (such checks are made every time the system space is returned to the user space). If there is a pending signal waiting to be processed and the signal is not blocked by the process, the process will remove the structure that the signal occupies in the pending signal chain before running the corresponding signal processing function. Whether the signal is removed from the process pending signal set is different for real-time and non-real-time signals. For the non-real-time signal, because in the outstanding signal information chain to occupy a maximum of one sigqueue structure, so that the structure is released, the signal should be removed in the process pending signal set (signal cancellation), and for real-time signal, may occupy the outstanding signal information chain in a plurality of sigqueue structure, Therefore it should be treated differently for the number of occupied gqueue structures: If only one sigqueue structure is used (the process only receives the signal once), then the signal should be removed in the process's pending signal set (signal logoff is complete). Otherwise, the signal is not removed from the pending signal set in the process (signal logoff is complete). The process will first log out of the process before executing the signal corresponding handler function.

4. Signal life is terminated. After the process logoff signal, immediately execute the corresponding signal processing function, after execution, the signal of this send to the impact of the process completely ended.
1) Whether the signal is registered or not, regardless of the function that sends the signal (such as Kill () or Sigqueue (), and the signal installation function (signal () and sigaction ()), only related to the signal value (signal value less than sigrtmin signal is only registered once, Signal value between Sigrtmin and Sigrtmax, as long as the process is received to be registered).
2) When the signal is written off to the corresponding signal processing function completion period, if the process receives the same signal multiple times, for the real-time signal, each time will be registered in the process, and for the non-real-time signal, no matter how many times the signal received, will be considered to receive only one signal, only in the process register once.

Signal "Pending" and "blocked"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.