2

Does Linux sends SIGCHLD to init (PID 1 process) when it inherits orphaned zombie processes (processes that have not been reaped by its original parent)?

  • just like with any other process, linux will send a SIGCHLD to init when one of its children has terminated (should that child be spawned by it or adopted). I don't see anything special about it, so maybe you should expand your Q with the actual stuff you find puzzling. – mosvy Jun 14 at 18:48
  • @mosvy the question here is how does init learn about adopted zombies? I think the SIGCHLD was already sent to the parent who failed to reap the zombie? – sourcejedi Jun 14 at 19:02
  • 2
    @sourcejedi "If it has exited notify the new parent about this child's death" -- just above the place you link to. – mosvy Jun 14 at 19:30
  • @mosvy When the live orphaned process dies, yes, but what about if it gets orphaned when it is already dead but not reaped? – user3368561 Jun 14 at 19:40
  • 1
    It will send a signal to the new parent, see the link from the comment above. Notice that the new parent is not necessarily init, see the comment before find_new_reaper(). (But the signal will always be SIGCHLD -- not the one configured via clone(2)). – mosvy Jun 14 at 23:48
1

Yep. I tested it. And you can see where this happens in the Linux code.


Test: Start a nested shell. From elsewhere, kill -s STOP the parent shell. Then kill -s KILL the child shell and then the parent.

Note:

If you try this inside gnome-terminal, for example, the reaper will not be PID 1. It will be a sub-reaper, the process systemd --user.

Also, systemd handles signals using a signalfd. So when you run strace -p on the systemd process, you will not see a signal being received. You will instead see that systemd wakes from epoll_wait() and performs a read() on a file descriptor.

You can confirm the file descriptor number is a signalfd using ls -l /proc/<PID>/fd/<FD>. It will say anon_inode:[signalfd].

  • you don't see it in the code because there's nothing special about it. there's no difference between the SIGCHLD sent to init and the SIGCHLD sent to another process, or between its natural and adopted children. – mosvy Jun 14 at 18:59
  • @mosvy hmm, if that's the case, how does init learn about adopted zombies? I think the SIGCHLD was already sent to the parent who failed to reap the zombie? – sourcejedi Jun 14 at 19:01
  • @mosvy edited, thanks for your update in the question comments. – sourcejedi Jun 14 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.