可以使用kill(SIGKILL, $$) 杀死正在休眠的Perl 程序吗?
我正在运行一个Perl程序,程序中有一个模块由外部进程触发,以杀死所有子进程并终止其执行。 这很好用。
但是,当某个函数如 xyz()
正在执行时,就会有一个关于条件的 sleep(60)
语句。
现在,该函数在等待某个值时会重复执行。
当我如上所述触发终止进程时,该进程不会发生。
有人知道为什么会发生这种情况吗?
I am running a Perl program, there is a module in the program which is triggered by an external process to kill all the child processes and terminate its execution.
This works fine.
But, when a certain function say xyz()
is executing there is a sleep(60)
statement on a condition.
Right now the function is executed repeatedly as it is waiting for some value.
When I trigger the kill process as mentioned above the process does not take place.
Does anybody have a clue as to why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白您如何在睡眠时试图从其内部杀死一个进程(您的
$$
问题主题)。如果您从不同的进程中杀死,那么它将有自己的$$。您需要首先找出要杀死的原始进程的 PID(通过跟踪进程列表或以某种方式与原始进程进行通信)。
杀死睡眠进程效果很好
这也适用于其他“杀死”信号('INT','ABRT','QUIT','TERM')
更新:重新阅读后,您的意思可能是“触发”通过外部进程”部分不会发生。如果是这种情况,您需要:
在进入睡眠状态之前在进程中设置一个 CATCHABLE 信号处理程序 (
$SIG{'INT'}
) - SIGKILL 无法被处理程序捕获.从所述“外部进程”发送 SIGINT
一旦 sleep() 被来自 SIGINT 处理程序的 SIGINT 中断,请执行所有所需的清理操作。
I don't understand how you are trying to kill a process from within itself (your
$$
in question subject) when it's sleeping.If you are killing from a DIFFERENT process, then it will have its own $$. You need to find out the PID of the original process to kill first (by trolling process list or by somehow communicating it from the original process).
Killing a sleeping process works very well
This also works with other "killish" signals ('INT', 'ABRT', 'QUIT', 'TERM')
UPDATE: Upon re-reading, may be the issue you meant was that "triggered by an external process" part doesn't happen. If that's the case, you need to:
Set up a CATCHABLE signal handler in your process before going to sleep (
$SIG{'INT'}
) - SIGKILL can not be caught by a handler.Send SIGINT from said "external process"
Do all the needed cleanup once sleep() is interrupted by SIGINT from SIGINT handler.