Re: Creating PID file



On Sun, Apr 27, 2008 at 9:30 AM, Michael Barnes <mbarnes@xxxxxxxxxxxx> wrote:
So, I need my script to
create a pidfile when it starts.


There's not trick for creating a pid file in Perl.
You can say,

my $pid = $$;
open my $fd,'>', "/path/program.pid" or die $!;
print $fd $pid;
close $pid or die $!;

at the begin of the script.
And at the END block of the script you should delete the pid file when
script was exiting:

END {
unlink "/path/program.pid" if $$ = $pid;
}


--
J. Peng - QQMail Operation Team
eMail: peng.kyo@xxxxxxxxx AIM: JeffHua
.



Relevant Pages

  • Re: pack and fcntl question
    ... and see strace output. ... I set F_SETLK in the script, but the perl returns F_SETLK64. ... so that's why I see the PID in the strace output. ...
    (perl.beginners)
  • scripting
    ... I'm writing one script that has a long execution time. ... I wont to retrieve PID of the process "script.sh" that is in background... ... No perl please (this runs on several machines and perl is not common on ...
    (comp.unix.solaris)
  • Re: ntpd dead but pid file exists
    ... I think its only the pid file, no process is running, there is not to kill. ...
    (RedHat)
  • Re: [SLE] PID file for java process?
    ... > I need to start a java process and get a valid pid for it to be able ... I don't get a pid file at all. ... Choose a directory for the PID file to which you have write access. ...
    (SuSE)
  • Re: service; ps & grep help
    ... pid file, but check the pid has not been recycled (daemon dies without ... new unrelated process gets the same pid)) you ...
    (Fedora)