Subject: | PGID does not exist after calling Proc::Daemon::Init() (POSIX::setsid()) |
Using perl 5.8.3 on Linux (specifically Fedora Core 2 (5+ years old))...
After doing Proc::Daemon::Init();
the current process group id is invalid (there is no process by that ID).
This is because the POSIX::setsid() is called after the first fork and
before the second.
The daemon I had written was attempting to send a signal to its process
group (an example I found in perlipc), and it took me a while to
diagnose why it wasn't working...
Specifically I had one process that forked and maintained a child (which
looped around a system call. The main process was set up to intercept
TERM and then pass it on to its children (using its process group):
kill(TERM => -$$);
But the children never got the signal, because they all belonged to a
process group that was surprisingly different than my main process.
I would end up with a ps listing like so:
PID PGID
102 101 main
103 101 second
104 101 third
main originally had a PID of 100... then Proc::Daemon::Init forked (PID
101), POSIX::setsid() (PGID 101), then forked again (PID 102).
So I couldn't use "-$$" to signal the obvious process group.
Trying to maintain my PIDs (particularly because I was doing a system())
seemed more complicated than necessary.
When I realized what was happening I called POSIX::setsid() after
calling Proc::Daemon::Init() and once again everything worked as expected.
So I don't know if you have an argument one way or another about the way
that it currently works, but at the very least I was confused and fooled
around (with the wrong code) for an hour.
So if there's a good reason for leaving the PGID at an unexistent
process, then I'd suggest that you at least document it.
Otherwise I appreciate the module (especially its simplicity)
and look forward to replacing some more old code I have with a simple
Proc::Daemon::Init() call.
Thanks!