SIGSEGV has asked for the wisdom of the Perl Monks concerning the following question:
Hello Perl IPC Wizards,
I have written a script to do some Unix/DBMS admin tasks while
running as a daemon.
I used the POSIX::setsid() call and did the usual preparations
as suggested in "perldoc perlipc" to auto-background.
Before that however I created a kind of semaphore file that holds the child's new PID of the daemon process and aqcuired an exclusive lock on it.
Despite, when I run the script anew while one daemon is running the flock call (that I or'ed to LOCK_NB in order to send a warning mail or something similar before the die()) returns a true value which screws my intended logic (provided there is any) altogether.
First I thought the reason lies in my usage of localized globs
for the filehandles that could go out of scope, and thus
close my semaphore file inadvertently.
But this can't be since I keep the refcount alive by returning
the file handle globs from the initilization sub which are
assigned to lexically scoped variables by the caller.
I also keep on logging to another file through one of these variables. So the refernces must still be valid.
Is the backgrounded child somehow losing the file lock by becoming a session leader?
I ask just for curiosity because I could easily insert some logic that sends a "kill 0 => $pid" to the PID read from the semaphore file to check if another deamon is running already. But I rather would like to do it by the use of file locks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Keeping File Locks after Daemonization (fork)
by tye (Sage) on Jan 30, 2003 at 18:46 UTC | |
|
Re: Keeping File Locks after Daemonization
by cees (Curate) on Jan 30, 2003 at 19:02 UTC | |
by zengargoyle (Deacon) on Jan 31, 2003 at 01:48 UTC | |
by cees (Curate) on Jan 31, 2003 at 05:11 UTC |