Wait for and/or kill process grandchildren produced by fork

后端 未结 3 1510
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 05:33

I fork() into process X and Y, afterwards Y forks() again into itself and process Z multiple times.

Now process Y is some kind of \"listene

3条回答
  •  無奈伤痛
    2020-12-20 06:03

    The only process that can acquire exit statuses from its distant Nth generation grand-children is the 'init' process, and that is a special case rule implemented by the kernel.

    In general, a process can only wait for its direct children to die; it cannot wait for its children's progeny to die.

    Morbid business...


    If you're in charge of the process Y code, or can influence it, perhaps that process should set signal(SIGCHLD, SIG_IGN) so that the Z processes do not create zombies. Process X could even do that itself while it forks the Y processes by ignoring SIGCHILD in the child process after the fork() and before any exec*() of the Y process. This only gets overridden if the Y processes explicitly set a different handler for SIGCHLD. And if the Y code explicitly sets SIGCHLD handling and does not actually collect its zombies (Z processes), then you can report a bug in the Y code.

提交回复
热议问题