Linux signal processing and multithreading Program

Source: Internet
Author: User

Look at apue and get some perceptual knowledge. However, different implementations do not have the same semantics for some functions, resulting in some confusion during programming. The following are some confusing points.

1. The implementation of the signal function BSD/Linux is not implemented when the signal processing function is called, but the signal is blocked during signal processing until the signal processing function returns. When other implementations call the signal processing function, the processing of the recovery signal is the default method. Therefore, the signal processing function must be rebuilt in the signal processing function to define the processing function, in these systems, a better way is to use sigaction to create a signal processing function.

2. Which thread will receive the signal sent to the process? Apue said thatProgramIf special signal blocking is not performed, when a signal is sent to the process, the system selects a thread to process the signal.

3. If some threads can shield a signal while some threads can process the signal, when we send this signal to a thread that cannot process the signal, the system will deliver the signal to the thread with the smallest process number that can process the signal.

4 if we register a signal processing function and use sigwait to wait for the signal at the same time, who will get the signal? In Linux, sigwait has a high priority.

5 In the POSIX thread model in Linux, a thread has an independent process number. You can use getpid () to obtain the thread number, and the thread number is saved in the value of pthread_t. The process number of the main thread is the process Number of the whole process. Therefore, sending a signal to the main process only sends the signal to the main thread. If the main thread sets signal shielding, the signal will be delivered to a thread that can be processed.

 

6 when you call the system function to execute shell commands, you can block sigchld with confidence, because the system will handle the problem of sub-Process Termination by itself.

 

7 when using sleep (), you need to block the sigalrm signal with confidence. Currently, the sleep function does not depend on the sigalrm signal of the alrm function.

 

To be continued

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.