2 ms·
From the service manager point of view, a daemonizing program is a headache. The program that the service manager thinks is starting immediately quits, and it'
by kazinator 2y ago
From the service manager point of view, a daemonizing program is a headache.
The program that the service manager thinks is starting immediately quits, and it's the grandchild (or even great grandchild) that's actually the payload service.
Because the parent quit, the grandchild becomes reparented to the init daemon; it is not a child of the service manager.
The service manager has no idea what the process ID of the service is.
If the self-daemonizing program writes its PID to a pidfile, and the service manaager is configured to know what that is and look for it, it can be obtained that way.
Not being the parent of the process, the service manager doesn't get notified when that process terminates. It has to use hacks to poll for it; like kill the PID with signal 0 to check liveness, and pray that the PID isn't recycled.
If you're writing a deamon program, make sure daemonization is optional, favoring opt-in over opt-out.
- JackSlateur 2y agocgroup is the only way to track a process and its children, as far as I know Either you use cgroup (in which case, neither the parent pid nor pidfile nor even the process ID are useful), either you do not (in which case, you leak processes) Stopping a service means, in the end, killing all processes in the associated cgroup.