File::Lockfile - create lockfile to prevent process simultaneous run
use File::Lockfile; my $lockfile = File::Lockfile->new( 'programname.pid', '/var/lock'); ... if ( my $pid = $lockfile->check ) { print "Seems that programname is already running with PID: $pid"; exit; } $lockfile->write; ... #somewhere in the end Lockfile->remove or $lockfile->remove;
File::Lockfile provides convenient interface for creating process pid file. While text file creating is very simple procedure, module performs additional checks if process is really running.
File::Lockfile
Initializes module with required arguments.
Checks if lockfile exists, returns PID of running process. Actually, routine also checks if process with PID stored in lockfile actually running.
my $pid = $lockfile->check;
Writes lockfile. Use it somewhere after checking if file exists
Removes lockfile. Manage it by yourself.
File::PID File::PID::Quick
Copyright 2008-2010, Sergey Sinkovskiy <glorybox@cpan.org>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install File::Lockfile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Lockfile
CPAN shell
perl -MCPAN -e shell install File::Lockfile
For more information on module installation, please visit the detailed CPAN module installation guide.