Signal pending and blocking"

Source: Internet
Author: User
Signal status:
The "pending" Status of the signal refers to the period from the generation of the signal to the time before the signal is processed. The "blocking" Status of the signal is a switching action, it indicates that the signal is blocked but not generated.
The example of apue blocks the exit signal with sigprocmask before sleep, then sleep, and generates an exit signal during sleep, but the exit signal is blocked at this time, ("blocking" in Chinese is easy to be misunderstood as a State. It is actually a switch-like action, so "blocked" rather than "blocked ") so it is in the pending status. After sleep, use sigprocmask to turn off the blocking switch of the exit signal, because the exit signal generated previously remains in the pending status. When the blocking switch is closed, exit the "pending" status immediately and get processed. This happens before sigprocmask returns.

Signal lifecycle:
For a complete signal Life Cycle (after the signal is sent to the corresponding processing function for execution), it can be divided into three important stages, which are characterized by four important events: 1. signal generation; 2. the signal is registered in the process. 3. the cancellation of the signal in the process is completed; 4. signal processing function execution is complete. The interval between two adjacent events forms a stage of the signal life cycle.
The following describes the practical significance of the four events:
1. Signal "birth ". The emergence of signals refers to the occurrence of events that trigger signals (such as hardware exceptions, Timer timeouts, and call of the signal sending function kill () or sigqueue ).

2. The signal is "registered" in the target process ";
Data members with pending signals in the task_struct structure of the process:
Struct sigpending pending;
Struct sigpending
{
Struct sigqueue * head, ** tail;
Sigset_t signal;
};
The first and second members point to the beginning and end of a sigqueue-type structure chain (called "pending signal information chain"), and the third member is all pending signal sets in the process, each sigqueue struct in the information chain depicts the information carried by a specific signal and points to the next sigqueue structure:
Struct sigqueue
{
Struct sigqueue * next;
Siginfo_t Info;
};
Signal registration means that the signal value is added to the pending Signal Set of the process (sigset_t signal, the second member of the sigpending structure ), the information carried by the signal is retained to a sigqueue structure of the pending signal information chain. As long as the signal is in the pending Signal Set of the process, it indicates that the process already knows the existence of the signal, but it has not been processed yet, or the signal is blocked by the process.
Note:
When a real-time signal is sent to a process, no matter whether the signal has been registered in the process or not, it will be re-registered. Therefore, the signal will not be lost, real-time signals are also called "reliable signals ". This means that the same real-time signal can occupy multiple sigqueue structures in the pending signal information chain of the same process (each process receives a real-time signal, A structure will be allocated for it to register the signal information, and the structure will be added at the end of the pending signal chain, that is, all generated real-time signals will be registered in the target process );
When a non-real-time signal is sent to a process, if the signal has been registered in the process, the signal will be discarded, resulting in signal loss. Therefore, non-real-time signals are also called "unreliable signals ". This means that the same non-real-time signal occupies at most one sigqueue structure in the pending signal information chain of the process (after a non-real-time signal is generated, (1) if the same signal has been registered in the target structure, it will not be registered. For a process, it is equivalent to not knowing that the current signal occurs and the signal is lost; (2), if the process's pending signals do not have the same signal, register yourself in the process ).

3. logout of the signal in the process. During the execution of the target process, the system checks whether a signal is waiting for processing (this is done every time the system space is returned to the user space ). If a pending signal is waiting for processing and the signal is not blocked by the process, the process will unload the structure occupied by the signal in the pending signal chain before running the corresponding signal processing function. Whether to delete signals from pending processes is different from real-time and non-real-time signals. For non-real-time signals, because only one sigqueue structure is occupied in the pending signal information chain, after the structure is released, the signal should be deleted in the pending Signal Set (the signal is canceled). For real-time signals, multiple sigqueue structures may be occupied in the pending signal information chain, therefore, the number of gqueue-occupied structures should be treated differently: if only one sigqueue structure is occupied (the process only receives this signal once ), then the signal should be deleted from the pending signal set in the process (the signal is canceled ). Otherwise, the signal is not deleted from the pending Signal Set of the process (the signal is canceled ). Before a process executes a signal processing function, it must first cancel the signal in the process.

4. Signal lifecycle termination. After the process cancels the signal, immediately execute the corresponding signal processing function. After the execution is complete, the effect of this sending of the signal on the process is completely ended.
Note:
1) whether the signal is registered is unrelated to the function of sending the signal (such as kill () or sigqueue () and the function of signal installation (signal () and sigaction, it is only related to the signal value (signals whose signal value is smaller than sigrtmin are registered only once at most. signals whose signal value is between sigrtmin and sigrtmax are registered as long as they are received by the process ).
2) when the signal is canceled to the corresponding signal processing function, if the process receives the same signal multiple times, the real-time signal will be registered in the process each time; for non-real-time signals, no matter how many signals are received, only one signal is received and registered only once in the process.

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: info-contact@alibabacloud.com 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.