流程重新父母:控制谁是新父母 [英] process re-parenting: controlling who is the new parent

查看:103
本文介绍了流程重新父母:控制谁是新父母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新父母总是初始化"还是是否有某种方法可以控制谁成为新父母?

Is the new parent always "init" or is there some way to control who gets to be the new parent?

维基百科似乎表明它总是"init".我真的希望事实并非如此.我已经尝试过使用setpgid和setsid可以想到的所有方法,但是没有运气.现在,我看到了这篇维基百科文章,我需要建议.

Wikipedia seems indicates that it's always "init". I really hope that this is not the case. I have tried everything I can think of with setpgid and setsid, but no luck. And now that I see this wikipedia article I need advice.

在类似Unix的操作系统中,任何 孤立的过程将立即 由特殊初始化系统采用 过程.该操作称为 重新父母,并自动发生. 即使从技术上讲 将"init"进程作为其父级, 它仍然被称为孤立过程 从最初的过程 创建它不再存在. 来自维基百科

In a Unix-like operating system any orphaned process will be immediately adopted by the special init system process. This operation is called re-parenting and occurs automatically. Even though technically the process has the "init" process as its parent, it is still called an orphan process since the process that originally created it no longer exists. Taken from wikipedia

我问的原因是因为我正在制作一个运行许多辅助进程的Mac应用程序.我希望这些工作进程在任务管理器.一些工作程序以不同的用户身份运行,在Mac OS X上,我需要分叉两次以将特权传递给子进程.因为我是双叉"的,所以这些工人当前是作为重做者运行的,因此当与任务管理器一起查看时,我看到这些工人将"init"作为其父进程.

The reason I'm asking is because I'm making a Mac app that runs a number of worker processes. I want these worker processes to appear as children of the main process in the process-hierarchy of the task manager. Some of the workers run as different users and on Mac OS X I need to fork twice to pass privileges to the child process. Because I "double fork" the workers currently run as deamons, and when looking with task manager I see the workers are having "init" as their parent process.

推荐答案

init始终采用孤立的子代.没有Unix将父级更改为某些非初始化进程的方法.

Orphaned children are always adopted by init. There is no Unix way of changing the parent to some non-init process.

从Linux 3.4开始,这不再严格成立.仍然没有可移植的Unix方式,但是正如Andy Lutomirski指出的那样,Linux 3.4为PR_SET_CHILD_SUBREAPER ="noreferrer"> prctl .

As of Linux 3.4 this is no longer strictly true. There's still no portable Unix way of doing this but as Andy Lutomirski points out Linux 3.4 adds PR_SET_CHILD_SUBREAPER for prctl.

实际上,次级收割者履行其init(1)的角色 后代进程.

In effect, a subreaper fulfills the role of init(1) for its descendant processes.

这篇关于流程重新父母:控制谁是新父母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆