IPC::Pidfile - run only one instance of a program at a time
version 0.02
Just import the module:
#!/usr/bin/env perl use IPC::Pidfile; ... # program code here
This will create a pidfile for the program and clear it up when the program is finished.
IPC::Pidfile is a module for use with Perl programs when you only want one instance of the script to run at a time. It should work for you if:
IPC::Pidfile
You are OK with the pidfile being created in the same directory as the script
You are not using an obscure OS. (Linux, BSD, OSX and Windows should be OK, see CPANTESTERS).
Your program is not using signal handlers for SIGINT and SIGTERM. IPC::Pidfile uses these to clear up the pidfile at the end of the process
SIGINT
SIGTERM
This module has a race condition as it attempts to remove the pidfile. It might be better to use IPC::Lockfile.
IPC::Lockfile
Race condition (see #WARNING).
This is an early release and may contain bugs. To run IPC::Pidfile in debug mode, create the environment variable IPC_PIDFILE_DEBUG:
IPC_PIDFILE_DEBUG
IPC_PIDFILE_DEBUG=1 ./path/to/program
David Farrell <dfarrell@cpan.org>
This software is Copyright (c) 2015 by David Farrell.
This is free software, licensed under:
The (two-clause) FreeBSD License
To install IPC::Pidfile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IPC::Pidfile
CPAN shell
perl -MCPAN -e shell install IPC::Pidfile
For more information on module installation, please visit the detailed CPAN module installation guide.