1# Signal 2 3 4## Basic Concepts 5 6Signal is a common asynchronous communication mechanism between processes. It uses software-simulated interrupt signals. When a process needs to communicate with another process, it sends a signal to the kernel. The kernel transfers the signal to the target process. The target process does not need to wait for the signal. 7 8 9## Working Principles 10 11The following table describes the APIs for signal operations. 12 13 **Table 1** Signal APIs (user-mode APIs) 14 15| Category | API | Description | 16| ---------------- | --------------------------------------------------- | ------------------------------------------------------------ | 17| Registering/Unregistering a signal callback| signal | Registers the main signal entry, and registers or unregisters a callback for a signal. | 18| Registering a signal callback| sigaction | Same as **signal**. This API is added with configuration options related to signal transmission. Currently, only some parameters in the **SIGINFO** structure are supported.| 19| Sending a signal | kill<br>pthread_kill<br>raise<br>alarm<br>abort | Sends a signal to a process or sends a message to a thread in a process, and sets the signal flag for a thread in a process. | 20| Invoking a callback | NA | Called by a system call or an interrupt. Before the switching between the kernel mode and user mode, the callback in the specified function in user mode is processed. After that, the original user-mode program continues to run.| 21 22> **NOTE**<br> 23> The signal mechanism enables communication between user-mode programs. The user-mode POSIX APIs listed in the above table are recommended. 24> 25> **Registering a Callback** 26> 27> 28> ``` 29> void *signal(int sig, void (*func)(int))(int); 30> ``` 31> 32> - Signal 31 is used to register the handling entry of the process callback. Repeated registration is not allowed. 33> 34> 35> - Signals 0 to 30 are used to register and unregister callbacks. 36> 37> 38> **Registering a Callback** 39> 40> 41> ``` 42> int sigaction(int, const struct sigaction ***restrict, struct sigaction ***restrict); 43> ``` 44> 45> You can obtain and modify the configuration of signal registration. Currently, only the **SIGINFO** options are supported. For details, see the description of the **sigtimedwait** API. 46> 47> **Sending a Signal** 48> 49> - Among the default signal-receiving behaviors, the process does not support **STOP**, **COTINUE**, and **COREDUMP** defined in POSIX. 50> 51> 52> - The **SIGSTOP**, **SIGKILL**, and **SIGCONT** signals cannot be shielded. 53> 54> 55> - If a process killed is not reclaimed by its parent process, the process becomes a zombie process. 56> 57> 58> - A process will not call back the signal received until the process is scheduled. 59> 60> 61> - When a process is killed, **SIGCHLD** is sent to its parent process. The signal sending action cannot be canceled. 62> 63> 64> - A process in the DELAY state cannot be woken up by a signal. 65