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 ]
name
$FindBin::Script
return: path to pid file
read pid from pid file
return: pid from pidfile or undef if pidfile not exists
write pid to pid file
pid => (int) process id [ default: $$ ]
pid
$$
return: 1 upon successfully writing the file or undef if it encountered an error
delete pid file
return: 1 if file successfully deleted, else 0
check if process running
name => (str) script name [ optional ]
return: pid if proces exists, undef if error, else 0
set / get pid file dir
default: /var/run
set / get pidfile suffix
default: empty sting
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.
To install PidFile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PidFile
CPAN shell
perl -MCPAN -e shell install PidFile
For more information on module installation, please visit the detailed CPAN module installation guide.