简体   繁体   English

在Linux中杀死并发出信号

[英]Kill and signal issue in linux

We have a lib which sends kill(pid, SIGUSR2) signal to the mentioned pid which is running most of the times in our case. 我们有一个库,它会向上述pid发送kill(pid, SIGUSR2)信号,在本例中,该pid大部分时间都在运行。 The process has signal command which has signal handling related to this signal. 该过程具有信号命令,该命令具有与此信号相关的信号处理。

I could see that this kill command is working and is returning success(0), but the corresponding signal handler is getting called some times and some times not. 我可以看到此kill命令正在运行并返回成功(0),但是相应的信号处理程序有时被调用,有时不被调用。

What could be the reason for this inconsistency? 这种不一致的原因可能是什么?

I got the solution to this, basically some other code is blocking the SIGUSR2 signal so i just unblocked it using sigprocmask(SIG_UNBLOCK, &set, NULL); 我得到了解决方案,基本上其他一些代码正在阻止SIGUSR2信号,因此我只是使用sigprocmask(SIG_UNBLOCK, &set, NULL);阻止sigprocmask(SIG_UNBLOCK, &set, NULL); and it worked. 而且有效。

The reason it happened only first time is the time duration it was blocked, basically they blocked for some time before unblocking and the code path execution here is that the first time this process is not able to pick the signal during that time. 它仅在第一次发生的原因是它被阻塞的持续时间,基本上它们在解除阻塞之前被阻塞了一段时间,这里的代码路径执行是该过程第一次无法在这段时间内拾取信号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM