| 1 |
NAME |
| 2 |
File::Pid - Pid File Manipulation |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use File::Pid; |
| 6 |
|
| 7 |
my $pidfile = File::Pid->new({ |
| 8 |
file => '/some/file.pid', |
| 9 |
}); |
| 10 |
|
| 11 |
$pidfile->write; |
| 12 |
|
| 13 |
if ( my $num = $pidfile->running ) { |
| 14 |
die "Already running: $num\n"; |
| 15 |
} |
| 16 |
|
| 17 |
$pidfile->remove; |
| 18 |
|
| 19 |
DESCRIPTION |
| 20 |
This software manages a pid file for you. It will create a pid file, |
| 21 |
query the process within to discover if it's still running, and remove |
| 22 |
the pid file. |
| 23 |
|
| 24 |
new |
| 25 |
my $pidfile = File::Pid->new; |
| 26 |
|
| 27 |
my $thisfile = File::Pid->new({ |
| 28 |
file => '/var/run/daemon.pid', |
| 29 |
}); |
| 30 |
|
| 31 |
my $thisfileandpid = File::Pid->new({ |
| 32 |
file => '/var/run/daemon.pid', |
| 33 |
pid => '145', |
| 34 |
}); |
| 35 |
|
| 36 |
This constructor takes two optional paramters. |
| 37 |
|
| 38 |
"file" - The name of the pid file to work on. If not specified, a pid |
| 39 |
file located in "File::Spec->tmpdir()" will be created that matches |
| 40 |
"(File::Basename::basename($0))[0] . '.pid'". So, for example, if $0 is |
| 41 |
~/bin/sig.pl, the pid file will be /tmp/sig.pl.pid. |
| 42 |
|
| 43 |
"pid" - The pid to write to a new pidfile. If not specified, $$ is used |
| 44 |
when the pid file doesn't exist. When the pid file does exist, the pid |
| 45 |
inside it is used. |
| 46 |
|
| 47 |
file |
| 48 |
my $pidfile = $pidfile->file; |
| 49 |
|
| 50 |
Accessor/mutator for the filename used as the pid file. |
| 51 |
|
| 52 |
pid |
| 53 |
my $pid = $pidfile->pid; |
| 54 |
|
| 55 |
Accessor/mutator for the pid being saved to the pid file. |
| 56 |
|
| 57 |
write |
| 58 |
my $pid = $pidfile->write; |
| 59 |
|
| 60 |
Writes the pid file to disk, inserting the pid inside the file. On |
| 61 |
success, the pid written is returned. On failure, "undef" is returned. |
| 62 |
|
| 63 |
running |
| 64 |
my $pid = $pidfile->running; |
| 65 |
die "Service already running: $pid\n" if $pid; |
| 66 |
|
| 67 |
Checks to see if the pricess identified in the pid file is still |
| 68 |
running. If the process is still running, the pid is returned. Otherwise |
| 69 |
"undef" is returned. |
| 70 |
|
| 71 |
remove |
| 72 |
$pidfile->remove or warn "Couldn't unlink pid file\n"; |
| 73 |
|
| 74 |
Removes the pid file from disk. Returns true on success, false on |
| 75 |
failure. |
| 76 |
|
| 77 |
program_name |
| 78 |
This is a utility method that allows you to determine what "File::Pid" |
| 79 |
thinks the program name is. Internally this is used when no pid file is |
| 80 |
specified. |
| 81 |
|
| 82 |
SEE ALSO |
| 83 |
perl. |
| 84 |
|
| 85 |
AUTHOR |
| 86 |
Casey West, <[email protected]>. |
| 87 |
|
| 88 |
COPYRIGHT |
| 89 |
Copyright (c) 2005 Casey West. All rights reserved. |
| 90 |
This module is free software; you can redistribute it and/or modify it |
| 91 |
under the same terms as Perl itself. |
| 92 |
|