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

问题描述

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

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

维基百科似乎表明它总是初始化".我真的希望情况不是这样.我已经用 setpgid 和 setid 尝试了我能想到的一切,但没有运气.现在我看到这篇维基百科文章,我需要一些建议.

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系统采用过程.这个操作叫做重新养育并自动发生.尽管从技术上讲这个过程将init"进程作为其父进程,它仍然被称为孤儿进程由于最初的过程创建它不再存在.摘自维基百科

我之所以这么问是因为我正在制作一个运行多个工作进程的 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.2.html" rel="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) 的角色,因为它的后代进程.

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

08-23 05:16