in reply to Re: Writing to flock files in a daemon
in thread Writing to flock files in a daemon
And yes, /tmp/_pid_file contains the PID.
This is fine until I run the script a second time, when /tmp/_pid_file gets truncated even though startup fails.
Any further suggestions?
# As before .. # ... sub main { my $start_mess = "===== Starting $TASK"; $start_mess .= " (@_)" if @_; $start_mess .= " ====="; error( $start_mess ); my $FH; open( HIGHLANDER, ">$PID_FILE") or die( "Cannot write to $PID_FILE +: $!" ); { my $count = 0; { flock HIGHLANDER, LOCK_EX | LOCK_NB and last; sleep 1; redo if ++$count < 3; error( "Script is already running." ); die( "Startup failed, PID file locked." ); } } $FH = select(HIGHLANDER); $| = 1; select($FH); print HIGHLANDER $$; # .. # ..as before..
<a href="http://www.graq.co.uk">Graq</a>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Writing to flock files in a daemon
by bluto (Curate) on Mar 07, 2002 at 17:36 UTC |