Re: get PID for a process

From: Willem Kossen (wjk100_at_iname.com)
Date: 08/08/03


Date: Fri, 08 Aug 2003 21:26:47 GMT


> > open pidFile, "/var/run/bla.pid"
> > print pidFile, "$$\n"
> > close pidFile
> > there's my pidfile and it works
>
> Well that example won't work because 1) you are opening the file for
> reading not writing and 2) the statements have to be separated with
> semicolons. A more correct example would be:
>
> ( my $prog = $0 ) =~ s!.*/!!s;
> open pidFile, ">/var/run/$prog.pid"
> or die "Cannot open /var/run/$prog.pid: $!";
> print pidFile, "$$\n";
> close pidFile;
>
Your so right, i retyped it in the email in stead of copying from the
script.

Thanks anyway

Willem



Relevant Pages

  • Re: one instance maximum of a bash script
    ... execute this script if another instance of the same script is running. ... I'm attaching the function I use to make the pidfile and check if the ... You must perform an atomic-test-and-set to do correct ... Just make sure the lock directory is on a local filesystem. ...
    (comp.os.linux.development.apps)
  • Re: Pidfile ends up in /tmp instead of /var/run [SOLVED]
    ... The script works as expected except for the pidfile ... # REQUIRE: NETWORKING DAEMON ... rc subsystem was responsible for creating the pid-file. ...
    (freebsd-questions)
  • Re: restart a script in etc/rc.d
    ... There is logic error in bacula rc.d script. ... It should first set ... If you don't set pidfile in rc.conf, pidfile is "" so it kills all bacula-fd's ...
    (freebsd-stable)
  • Re: [opensuse] Script to check interface & restart network service
    ... You could go and get the pid from the runfile and kill the script ... Ah, and yes, most daemons have a pidfile in /var/run/ for a reason. ...
    (SuSE)
  • one instance maximum of a bash script
    ... I'm writing a bash script and I don't want for a user to be able to execute ... I'm attaching the function I use to make the pidfile and check if the ... I would need a sort of atomic operation ... echo $$> $pidfile ...
    (comp.os.linux.development.apps)