可以使用kill(SIGKILL, $$) 杀死正在休眠的Perl 程序吗?

发布于 2024-12-04 09:28:50 字数 223 浏览 0 评论 0原文

我正在运行一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔日梦未散 2024-12-11 09:28:50

我不明白您如何在睡眠时试图从其内部杀死一个进程(您的 $$ 问题主题)。

如果您从不同的进程中杀死,那么它将有自己的$$。您需要首先找出要杀死的原始进程的 PID(通过跟踪进程列表或以某种方式与原始进程进行通信)。

杀死睡眠进程效果很好

$ ( date ; perl5.8 -e 'sleep(100);' ; date ) &

   Wed Sep 14 09:48:29 EDT 2011

$ kill -KILL 8897

   Wed Sep 14 09:48:54 EDT 2011

这也适用于其他“杀死”信号('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

$ ( date ; perl5.8 -e 'sleep(100);' ; date ) &

   Wed Sep 14 09:48:29 EDT 2011

$ kill -KILL 8897

   Wed Sep 14 09:48:54 EDT 2011

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文