达尔文:如何在不杀死子进程的情况下杀死父进程?
在 OS X 10.4/5/6 上:
我有一个生成子进程的父进程。我想杀死父母而不杀死孩子。是否可以?我可以修改任一应用程序上的源。
On OS X 10.4/5/6:
I have a parent process which spawns a child. I want to kill the parent without killing the child. Is it possible? I can modify source on either app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 NSD 所问的,这实际上取决于它是如何产生的。例如,如果您使用的是 shell 脚本,则可以使用 nohup 命令来运行子进程。
如果您使用的是
fork/exec
,那么它会稍微复杂一些,但也不会太复杂。来自 http://code.activestate.com/recipes/66012/
这是其中之一有史以来最好的书。它非常详细地涵盖了这些主题。
UNIX 环境中的高级编程,第二版(Addison-Wesley 专业计算系列)(平装本)
ISBN-10: 0321525949
ISBN-13:978-0321525949
5 星亚马逊评论(我会给它 6 分)。
As NSD asked, it really depends on how it is spawned. If you are using a shell script, for example, you can use the
nohup
command to run the child through.If you are using
fork/exec
, then it is a little more complicated, but no too much so.From http://code.activestate.com/recipes/66012/
This is one of the best books ever written. It covers these topics in great and extensive detail.
Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series) (Paperback)
ISBN-10: 0321525949
ISBN-13: 978-0321525949
5 star amazon reviews (I'd give it 6).
如果父级是 shell,并且您想要启动长时间运行的进程然后注销,请考虑
nohup (1)
或disown
。如果您控制子级的编码,则可以捕获 SIGHUP 并以某种非默认方式处理它(例如完全忽略它)。请阅读
signal (3)
和sigaction (2)
手册页以获取相关帮助。无论哪种方式,StackOverflow 上都有几个现有的问题,并提供了很好的帮助。If the parent is a shell, and you want to launch a long running process then logout, consider
nohup (1)
ordisown
.If you control the coding of the child, you can trap SIGHUP and handling it in some non-default way (like ignoring it outright). Read the
signal (3)
andsigaction (2)
man pages for help with this. Either way there are several existing questions on StackOverflow with good help.