changing a process's parent

前端 未结 2 758
耶瑟儿~
耶瑟儿~ 2020-12-17 14:57

Is it possible to change a process parent?
ex: parent A has Child B can I make the parent of B is the Init process without killing A?

2条回答
  •  离开以前
    2020-12-17 15:26

    Not from outside of process B.

    From inside process B, you can call fork which makes a copy of your process, then let the original exit. When that happens the new copy B2 will not be a child of A, its parent will be set to 1 (the init process).

提交回复
热议问题