正确的 kill 系统调用 linux 使用模式

correct kill syscall linux usage pattern

man 对于 int kill(pid_t pid, int sig); 说:

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.

这是否意味着如果我的程序 运行 具有 root 权限并且它不小心(由于内存损坏或黑客攻击)提供 -1 作为 pid 参数 - 这将导致整个系统的完整 DoS?

如果是这样,是否建议在调用此潜在灾难性调用之前始终对 pid 参数值执行双重检查? (只是说)

Does this mean that if my program is run with root permissions and it accidentally (due to memory corruption or a hack) provides -1 as pid argument - this will cause a complete DoS for the entire system?

是的,这种情况是可能的。但它发生的可能性非常小。因为没有 运行 具有 root 权限的程序会做这样的事情。如果恶意 user/binary 以某种方式获得了 root 权限,那么发送信号只是问题之一。

If so, is it recommended to always perform a double check for the pid argument value before calling this potentially disastrous call?

那只是超级 pa运行oid 的想法。祸不单行的方法千千万万activities.You不妨担心一下:

如果系统启动时 运行 没有恶意守护进程会怎样:

kill(-1, SIGKILL);

您怎么知道您创建的库函数是否不会调用 reboot(2) 并重新启动您的系统?

等等

此外,PID 不仅仅是用户提供的需要清理的值。 PID 主要是使用系统调用或库调用在程序中获取的值。所以 "accidentally" 使用 -1 的可能性为零。基本上,您 someone/program 拥有 root 权限并决定搞砸您的系统,那么您无能为力。