有没有办法判断一个进程是否是 child 如果它确实 fork 然后 setsid

is there a way to tell if a process is a child if it did fork and then setsid

如果一个进程做了 fork 然后 child 做了 setsid,有没有办法告诉它是第一个进程的 child?有什么办法可以杀死这样的进程及其 parent?

setsid 不会破坏 parent/child 关系。所以你仍然可以获得进程的children,e。 G。如所述 here(link 我们 ubuntu 具体,但这适用于任何其他发行版)。

parent 进程总是可以很容易地跟踪它的直接 children,因为 fork returns 它们的 id(grand children 得到更多 tricky。 ..) 并在退出时(优雅地)向其任何 children 发送信号。

prctl(PR_SET_PDEATHSIG, <signal>)(使 children 接收信号的便捷方式,如果 parent 死亡),也将在调用 setsid 后继续存在。