1 Star 0 Fork 4.9K

丛林 / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
kernel-small-basic-trans-user-signal.md 6.30 KB
一键复制 编辑 原始数据 按行查看 历史
Annie_wang 提交于 2022-08-12 10:03 . update docs

Signal

Basic Concepts

Signal is a common inter-process asynchronous communication mechanism. It uses software-simulated interrupt signals. When a process needs to communicate with another process, it sends a signal to the kernel. The kernel then transfers the signal to the destination process. The destination process does not need to wait for the signal.

Working Principles

The following table describes the APIs available for signal operations.

Table 1 Signal operation process and APIs (user-mode APIs)

Function

API

Description

Registering the signal callback

signal

Registers the main signal entry, and registers and unregisters the callback function of a signal.

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.

Sending signals

kill

Sends a signal to a process or sends messages to a thread in a process, and sets signal flags for threads in a process.

pthread_kill

raise

alarm

abort

Triggering a callback

None

Triggered by a system call or an interrupt. Before the switching between the kernel mode and user mode, the specified function in user mode is entered, and the corresponding callbacks are processed. After that, the original user-mode program continues to run.

NOTE: The signal mechanism enables communication between user-mode programs. The user-mode POSIX APIs listed in the above table are recommended. Register a callback function.

void *signal(int sig, void (*func)(int))(int);

a. Signal 31 is used to register the handling entry of the process callback. Repeated registration is not allowed. b. Signals 0 to 30 are used to register and unregister callbacks. Register a callback.

int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict);

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. Transmit a signal. a. Among the default signal-receiving behaviors, the process does not support STOP, CONTINUE, and COREDUMP defined in the POSIX standard. b. The SIGSTOP, SIGKILL, and SIGCONT signals cannot be shielded. c. If a process killed is not reclaimed by its parent process, the process becomes a zombie process. d. A process will not call back the signal received until the process is scheduled. e. When a process is killed, SIGCHLD is sent to its parent process. The signal sending action cannot be canceled. f. A process in the DELAY state cannot be woken up by a signal.

1
https://gitee.com/jungle8023/docs.git
git@gitee.com:jungle8023/docs.git
jungle8023
docs
docs
master

搜索帮助