Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: Creating PI...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 25 Topic 10992 of 11518
Post > Topic >>

Re: Creating PID file

by chas.owens@[EMAIL PROTECTED] (Chas. Owens) Apr 27, 2008 at 04:53 AM

On Sun, Apr 27, 2008 at 2:49 AM, Michael Barnes <MBarnes@[EMAIL PROTECTED]
>
wrote:
> My apologies.  I know this is a cross-platform group, and that is fine. 
However, if you are unable to understand simple Linux terminology, then it
is doubtful that you can help answer my question.  If the description is
nonsense to you, then please don't waste your or my time in an apparent
slam on my choice of operating systems.  If your reply represents the
general attitude of this list, then it looks like I've come to the wrong
place for assistance.
>
>  But, to simplify my request, a pid is a process id.  In Linux, the
command 'ps' will give a listing of process IDs.
>  I need the script to determine its own pid, then write that to a file.
snip

The variable $$ holds the PID for the current program*.  Typically a
pidfile is created in /var/run by saying something like

use strict;
use warnings;
use File::Basename;

BEGIN {
    our $program = basename $0;
    die "$program already running\n" if -f "/var/run/$program";
    open my $pidfile, ">", "/var/run/$program"
        or die "could not open /var/run$program: $!";
    print $pidfile "$$\n";
    close $pidfile;
}

#make sure the last thing done is the removal of the pidfile
#note: this happens even if we die
END {
    our $program;
    unlink("/var/run/$program")
        or die "could not delete /var/run/$program";
}

#the rest of your code

There are also a few modules on CPAN that automate this to a certain
extent for you: Proc::Pidfile**, File::Pid***, and
File::Pid::Quick****.

* see perldoc perlvar or
http://perldoc.perl.org/perlvar.html#$PROCESS_ID
for more information
** http://search.cpan.org/dist/Proc-Pidfile/Pidfile.pm
*** http://search.cpan.org/dist/File-Pid/lib/File/Pid.pm
**** http://search.cpan.org/dist/File-Pid-Quick/Quick.pm
-- 
Chas. Owens
wonkden.net
The most im****tant skill a programmer can have is the ability to read.
 




 25 Posts in Topic:
Creating PID file
mbarnes@[EMAIL PROTECTED]  2008-04-26 20:30:17 
Re: Creating PID file
rob.dixon@[EMAIL PROTECTE  2008-04-27 02:49:47 
RE: Creating PID file
MBarnes@[EMAIL PROTECTED]  2008-04-26 23:49:23 
RE: Creating PID file
MBarnes@[EMAIL PROTECTED]  2008-04-27 17:24:54 
Re: Creating PID file
rob.dixon@[EMAIL PROTECTE  2008-04-28 06:48:29 
Re: Creating PID file
chas.owens@[EMAIL PROTECT  2008-04-27 04:53:22 
Re: Creating PID file
peng.kyo@[EMAIL PROTECTED  2008-04-27 16:59:52 
Re: Creating PID file
chas.owens@[EMAIL PROTECT  2008-04-27 05:03:56 
Re: Creating PID file
peng.kyo@[EMAIL PROTECTED  2008-04-27 09:50:51 
Re: Creating PID file
peng.kyo@[EMAIL PROTECTED  2008-04-27 10:36:11 
sql and perl
rich.japh@[EMAIL PROTECTE  2008-04-26 23:24:22 
Re: sql and perl
orasnita@[EMAIL PROTECTED  2008-04-27 11:06:23 
Re: sql and perl
rich.japh@[EMAIL PROTECTE  2008-04-27 12:25:59 
Re: sql and perl
rvtol+news@[EMAIL PROTECT  2008-04-28 09:54:43 
Re: sql and perl
rob.dixon@[EMAIL PROTECTE  2008-04-28 09:20:07 
Re: sql and perl
rich.japh@[EMAIL PROTECTE  2008-04-28 10:19:51 
Re: sql and perl
peng.kyo@[EMAIL PROTECTED  2008-04-27 11:34:01 
Re: sql and perl
rich.japh@[EMAIL PROTECTE  2008-04-26 23:42:24 
Re: Creating PID file
orasnita@[EMAIL PROTECTED  2008-04-27 10:56:58 
Re: sql and perl
dan@[EMAIL PROTECTED] (D  2008-04-28 18:15:36 
Re: sql and perl
ficovh@[EMAIL PROTECTED]   2008-04-28 10:40:29 
Re: sql and perl
rob.dixon@[EMAIL PROTECTE  2008-04-28 17:52:53 
RE: sql and perl
rvm@[EMAIL PROTECTED] (B  2008-04-28 14:40:25 
Re: sql and perl
rob.dixon@[EMAIL PROTECTE  2008-04-28 20:06:21 
RE: sql and perl
andrew.curry@[EMAIL PROTE  2008-04-29 00:09:11 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 13:10:29 CDT 2008.