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