在启动时暂停分叉进程
我想在启动时暂停(暂停)分叉进程并稍后恢复它。有没有办法用 POSIX 或 Solaris 来做到这一点?
I want to suspend (pause) a forked process at startup and resume it later on. Is there any way to do that with POSIX or Solaris.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不在 fork 后在子进程的代码中调用
pause()
呢?Why not just call
pause()
in code of child process after fork?我通过使用信号量和信号处理程序来做到这一点。为了唤醒子进程,父进程向子进程发送信号,子进程又从信号处理程序中发布信号量。然后,等待信号量的孩子醒来了。
I did it by using a semaphore and a signal handler. To wake up the child, the parent process sends a signal to the child process which in turn posts the semaphore from within the signal handler. The child, which was waiting on that semaphore, then wakes up.
您可以发送进程
SIGSTOP
,然后使用SIGCONT
恢复。You could send your process
SIGSTOP
, then resume withSIGCONT
.