挂起子进程

发布于 2024-07-14 00:05:12 字数 116 浏览 7 评论 0原文

我正在尝试测试我的系统并希望模拟子进程挂起的情况。 为此,我尝试将子进程附加到 GDB 并对其进行中断。 但事情似乎并没有按预期进行。

另外,同样,我如何知道生成的子进程没有进行,而是挂起?

I am trying to test out my system and wish to emulate a condition, where the child process gets hung. For doing this, I am trying to attach the child process to GDB and putting a break on it. But things don't seem to be going as expected.

Also, in the same vein, how do I know that a spawned child process is not progressing, but is hung?

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

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

发布评论

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

评论(2

不弃不离 2024-07-21 00:05:12

可以使用 SIGSTOP 来挂起子进程 - 但这与子进程进入无限循环或错误的条件等待明显不同 - 但它可能足够接近测试。

要检查子进程没有挂起,您可以让它向父进程发送心跳(为此您需要某种通信通道 - 至少可能是标准输入/标准输出)。 如果孩子未能发送几条心跳消息,那么孩子就会挂起。

Use can use SIGSTOP to hang a child process - but that is observably different from the child process going into an infinite loop, or a bad conditional wait - still it may be close enough for testing.

To check a child process has not hung, you have it send heart-beats to the parent (you'll need some kind of communications channel for this - maybe stdin/stdout at a minimum). Then the child has hung if it fails to send a couple of heart-beats messages.

‖放下 2024-07-21 00:05:12

子进程将继承在 fork 之前创建的任何管道。 您可以使用它来“挂起”您的孩子并让它知道何时继续。 您可以让您的子进程尝试在管道上进行阻塞读取,它将阻塞(即挂起),直到父进程写入内容。

您还可以使用道格拉斯提到的信号。 您可以让操作系统执行基本的停止/继续操作,也可以实现信号处理程序来执行更复杂的操作(例如进入无限循环)。

这两个示例都可以在 Unix 编程常见问题解答中找到以及大量有关进程控制、信号处理、管道等的附加信息...

您可以尝试查看 /proc 以确定您是否挂起。 您可以读取 /proc//stat 来获取大量低级进程信息,包括当前状态、进程已调度的用户/内核时间量、当前堆栈和指令指针等...结合使用此功能,您可以尝试确定进程是否挂起。 查看 proc(5) 手册页,了解有关 /proc/< 的更多信息。 pid>/统计。

A child process will inherit any pipes created before the fork. You can use this to both "hang" your child and to let it know when to continue. You can have your child process try a blocking read on the pipe, and it will block (i.e. hang) until the parent writes something.

You could also use signals like Douglass mentions. You can let the OS do basic stop/cont or you can implement signal handlers to do something more complex (like entering an infinite loop).

Examples for both of these can be found in the Unix Programming FAQ along with a ton of additional information on process control, signal handling, pipes, etc...

You can try looking in /proc to determine if you are hung. You can read /proc/<child-pid>/stat to get a lot of low-level process information including the current state, the amount of user/kernel time the process has been scheduled, the current stack and instruction pointers, etc... Using a combination of this you can try to determine if the process is hung or not. Check out the proc(5) man page for more info on /proc/<pid>/stat.

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