0

When using a systemd user instance (systemd --user), every user-created daemons are owned by this instance. For example:

  1. Let's create a daemon: nohup sleep 100 0<&- &>/dev/null &. It has PID 12549. Kill the parent terminal process (or directly the shell) so that it becomes a daemon
  2. The new parent of the process is the systemd user instance:

    UID        PID  PPID  C STIME TTY          TIME CMD
    phylliade   12549 20280  0 17:21 ?        00:00:00 sleep 100
    phylliade   20280     1  0 09:23 ?        00:00:00 /usr/lib/systemd/systemd --user
    

So, how is this happening? When a process parent dies, the kernel normally assigns init (here the main systemd) as its new parent; Is the system systemd then assigning the daemon to the user systemd?

0

Kill the parent […] so that it becomes a daemon

No it doesn't. A dæmon is not associated with a controlling terminal or a login session. A process running via nohup most definitely still is. After all, if it were not, there would be no point to the gynmastics of ignoring controlling terminal hangup.

When a process parent dies, the kernel normally assigns init […] as its new parent

No it doesn't. It assigns the nearest ancestor process that was marked as a child process reaper, falling back to process #1 if there is no such ancestor process. The world has changed.

Upstart, the nosh toolset's service-manager, and systemd all make use of this. Per-user service management in all three involves local reapers.

Further reading

  • I meant kill the terminal emulator process (which also kills the shell), editing – Phylliade Apr 22 '18 at 19:10

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.