
PidFile - simple read / write pidfile

use PidFile;
# read pidfile
my $pid = PidFile->Read;
if ( $pid ) {
# pid file for this script arealdy exists
# check if script running
if ( PidFile->Check( "pid" => $pid ) {
# script running, so i die
confess;
}
# script not running, delete old pidfile
PidFile->Delete;
}
# save new pid file
PidFile->Write;
## or you can run just only
PidFile->Write;
## and this function check if old pidfile exists and if script running

PidFile provide very simple class methods to manages a pidfile for the current or any process.

get path to pid file
input (hash):
name => (str) script name [ default: $FindBin::Script ]
return: path to pid file
read pid from pid file
input (hash):
name => (str) script name [ default: $FindBin::Script ]
return: pid from pidfile or undef if pidfile not exists
write pid to pid file
input (hash):
pid => (int) process id [ default: $$ ]
name => (str) script name [ default: $FindBin::Script ]
return: 1 upon successfully writing the file or undef if it encountered an error
delete pid file
input (hash):
name => (str) script name [ default: $FindBin::Script ]
return: 1 if file successfully deleted, else 0
check if process running
input (hash):
pid => (int) process id [ default: $$ ]
name => (str) script name [ optional ]
return: pid if proces exists, undef if error, else 0


Lukasz Romanowski (roman) <lroman@cpan.org>

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.