/usr/share/perl5/MMM/Common/PidFile.pm is in mysql-mmm-common 2.2.1-1.1.
This file is owned by root:root, with mode 0o664.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | package MMM::Common::PidFile;
use strict;
use warnings FATAL => 'all';
use English qw( PROCESS_ID );
use Log::Log4perl qw(:easy);
our $VERSION = '0.01';
sub new($$) {
my $self = shift;
my $path = shift;
return bless { 'path' => $path }, $self;
}
sub exists($) {
my $self = shift;
return -f $self->{path};
}
sub is_running($) {
my $self = shift;
return 0 unless $self->exists();
open(PID, $self->{path}) || LOGDIE "Can't open pid file '$self->{path}' for reading!\n";
chomp(my $pid = <PID>);
close(PID);
return kill(0, $pid);
}
sub create($) {
my $self = shift;
open(PID, ">" . $self->{path}) || LOGDIE "Can't open pid file '$self->{path}' for writing!\n";
print PID $PROCESS_ID;
close(PID);
DEBUG "Created pid file '$self->{path}' with pid $PROCESS_ID";
}
sub remove($) {
my $self = shift;
unlink $self->{path};
}
1;
__END__
=head1 NAME
MMM::Common::Pidfile - Manage process id files
=cut
=head1 SYNOPSIS
my $pidfile = new MMM::Common::PidFile:: '/path/to/your.pid';
# create pidfile with current process id
$pidfile->create();
# check if pidfile exists
$pidfile->exists();
# check if the process with the process id from the pidfile is still running
$pidfile->is_running();
# remove pidfile
$pidfile->remove();
=cut
|