gpt4 book ai didi

c - 如何将信号传递给另一个进程?

转载 作者:行者123 更新时间:2023-11-30 20:00:58 24 4
gpt4 key购买 nike

通过查看信号的语法,我可以看到它没有提供将信号传递给另一个 pid (pid_t) 的灵 active 。进程只能忽略、执行默认操作或对其自身进行自定义操作。我们可以通过哪些方式将信号传递给另一个进程? (我不是在谈论 pthreads)。

最佳答案

您想要 kill(2) system call (不是 kill shell 命令):

#include <sys/types.h>
#include <signal.h>

int kill(pid_t pid, int sig);

The kill() system call can be used to send any signal to any process group or process.

If pid is positive, then signal sig is sent to the process with the ID specified by pid.

If pid equals 0, then sig is sent to every process in the process group of the calling process.

If pid equals -1, then sig is sent to every process for which the calling process has permission to send signals, except for process 1 (init), but see below.

If pid is less than -1, then sig is sent to every process in the process group whose ID is -pid.

If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a process ID or process group ID.

运行 man Kill 将为您提供kill(1),这是 shell 命令。要获取系统调用的手册页,请运行 man 2 Kill

关于c - 如何将信号传递给另一个进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37398364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com