[英]Will kill be interrupted by a signal?
For example, if I use kill (a function in C library signal.h) to emit a SIGINT signal to a child, will the SIGCHLD signal from the child be caught before the kill function returns?例如,如果我使用 kill (a function in C library signal.h) 向孩子发出 SIGINT 信号,那么来自孩子的 SIGCHLD 信号会在 kill ZC1C425268E68384F14AB50 返回之前被捕获吗?
While the kill
syscall isn't interruptible (at least according to the man page ), there's still at least two cases in which the SIGCHLD
handler could run before the function returns:虽然
kill
系统调用不可中断(至少根据手册页),但仍有至少两种情况下SIGCHLD
处理程序可以在 function 返回之前运行:
kill
syscall returns in your first thread.kill
系统调用返回之前选择在那里运行信号处理程序。kill
from your libc.kill
。 The signal handler could run in between the syscall returning to it, and it returning to your code. So if you want to make sure you don't get the SIGCHLD
until after kill
returns, then you need to use sigprocmask
to block it before the kill
until you're ready for it.因此,如果您想确保在
kill
返回之前不会获得SIGCHLD
,那么您需要在kill
返回之前使用sigprocmask
来阻止它,直到您准备好为止。
I don't know if this answers your question but, reading the Linux man page, the possible return values of kill
are EINVAL
, EPERM
, and ESRCH
.我不知道这是否回答了您的问题,但是,阅读 Linux 手册页,
kill
的可能返回值是EINVAL
、 EPERM
和ESRCH
。 EINTR
is not one of them. EINTR
不是其中之一。 That makes me think that the function won't be interrupted.这让我觉得 function 不会被打断。 At least, the system call won't be interrupted.
至少,系统调用不会被中断。
EDIT: I mean errno
, not return, values.编辑:我的意思是
errno
,而不是返回值。
Signal handling is asynchronous.信号处理是异步的。 There is therefore no guarantee either way about whether the
SIGCHLD
emitted when the child terminates will be received by the parent before the kill
call returns.因此,无论哪种方式都不能保证子进程终止时发出的
SIGCHLD
是否会在kill
调用返回之前被父进程接收。 My guess would be that kill
will usually win the race and return before the SIGCHLD
arrives, but it is not safe to depend on that.我的猜测是
kill
通常会在SIGCHLD
到达之前赢得比赛并返回,但依赖它是不安全的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.