向子进程发送 SIGSTOP 会停止所有执行。 C

发布于 2024-09-26 02:19:10 字数 143 浏览 1 评论 0原文

当我从父进程调用 kill(Child_PID, SIGSTOP); 时,我希望子进程停止执行,而父进程继续执行。这是预期的行为还是我必须在子进程中显式声明 SIGSTOP 处理程序?我到处搜索都没有找到这个信息。

谢谢。 布雷登

When I call kill(Child_PID, SIGSTOP); from the parent, I expect the child to halt execution and the parent to continue. Is that the expected behavior or do I have to explicitly declare the SIGSTOP handler in the child? I have searched everywhere and not been able to find this information.

Thanks.
Braden

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

甜味拾荒者 2024-10-03 02:19:10

POSIX 说:

系统不应允许进程捕获信号 SIGKILL 和 SIGSTOP。

因此,如果信号发送成功,孩子别无选择,只能停止。并且您不能在子(或父或任何其他)进程中设置 SIGSTOP 处理程序。

POSIX says:

The system shall not allow a process to catch the signals SIGKILL and SIGSTOP.

So, the child has no option but to stop - if the signal is sent successfully. And you cannot set a SIGSTOP handler in the child (or parent, or any other) process.

桃扇骨 2024-10-03 02:19:10

这是预期的行为。

使用 strace your_program 查看发生了什么。

This is the expected behavior.

Use strace your_program to see what's happening.

策马西风 2024-10-03 02:19:10

这是预期的行为。引用unix手册页:

信号 SIGKILL 和 SIGSTOP 无法被捕获、阻止或忽略。

BSD 手册页提到:

signal() 函数将失败并且不会执行任何操作
如果发生以下情况之一:

[EINVAL] sig 参数不是有效的信号号。
[EINVAL] 尝试忽略或提供处理程序
                   对于 SIGKILL 或 SIGSTOP。

最后,您不允许安装 SIGSTOP 处理程序。并且进程将保持挂起状态,直到收到SIGCONT

That's the expected behaviour. Quoting from the unix man page:

The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.

And the BSD man page mentions that:

The signal() function will fail and no action will take place
if one of the following occur:

[EINVAL]           The sig argument is not a valid signal number.
[EINVAL]           An attempt is made to ignore or supply a handler
                   for SIGKILL or SIGSTOP.

Concluding, you're not permitted to install a handler for SIGSTOP. And the process will remain in the suspended state until it receives a SIGCONT.

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