1File::Pid(3)          User Contributed Perl Documentation         File::Pid(3)
2
3
4

NAME

6       File::Pid - Pid File Manipulation
7

SYNOPSIS

9         use File::Pid;
10
11         my $pidfile = File::Pid->new({
12           file => '/some/file.pid',
13         });
14
15         $pidfile->write;
16
17         if ( my $num = $pidfile->running ) {
18             die "Already running: $num\n";
19         }
20
21         $pidfile->remove;
22

DESCRIPTION

24       This software manages a pid file for you. It will create a pid file,
25       query the process within to discover if it's still running, and remove
26       the pid file.
27
28   new
29         my $pidfile = File::Pid->new;
30
31         my $thisfile = File::Pid->new({
32           file => '/var/run/daemon.pid',
33         });
34
35         my $thisfileandpid = File::Pid->new({
36           file => '/var/run/daemon.pid',
37           pid  => '145',
38         });
39
40       This constructor takes two optional paramters.
41
42       "file" - The name of the pid file to work on. If not specified, a pid
43       file located in "File::Spec->tmpdir()" will be created that matches
44       "(File::Basename::basename($0))[0] . '.pid'". So, for example, if $0 is
45       ~/bin/sig.pl, the pid file will be /tmp/sig.pl.pid.
46
47       "pid" - The pid to write to a new pidfile. If not specified, $$ is used
48       when the pid file doesn't exist. When the pid file does exist, the pid
49       inside it is used.
50
51   file
52         my $pidfile = $pidfile->file;
53
54       Accessor/mutator for the filename used as the pid file.
55
56   pid
57         my $pid = $pidfile->pid;
58
59       Accessor/mutator for the pid being saved to the pid file.
60
61   write
62         my $pid = $pidfile->write;
63
64       Writes the pid file to disk, inserting the pid inside the file.  On
65       success, the pid written is returned. On failure, "undef" is returned.
66
67   running
68         my $pid = $pidfile->running;
69         die "Service already running: $pid\n" if $pid;
70
71       Checks to see if the pricess identified in the pid file is still
72       running. If the process is still running, the pid is returned.
73       Otherwise "undef" is returned.
74
75   remove
76         $pidfile->remove or warn "Couldn't unlink pid file\n";
77
78       Removes the pid file from disk. Returns true on success, false on
79       failure.
80
81   program_name
82       This is a utility method that allows you to determine what "File::Pid"
83       thinks the program name is. Internally this is used when no pid file is
84       specified.
85

SEE ALSO

87       perl.
88

AUTHOR

90       Casey West, <casey@geeknest.com>.
91
93         Copyright (c) 2005 Casey West.  All rights reserved.
94         This module is free software; you can redistribute it and/or modify it
95         under the same terms as Perl itself.
96
97
98
99perl v5.36.0                      2022-07-22                      File::Pid(3)
Impressum