Proc::tored::PidFile - Manage a service using a pid file
version 0.15
use Proc::tored::PidFile; my $pidfile = Proc::tored::PidFile->new($pid_file_path); if (my $lock = $pidfile->lock) { run_service; } else { die "service is already running under process id " . $pidfile->running_pid; }
Allows the use of a pid file to manage a running service.
Returns true if the pid indicated by the pid file is the current process.
Returns true if the pid indicated by the pid file is an active, running process. This is determined by attempting to signal the process using kill(0, $pid).
kill(0, $pid)
Returns the pid stored in the pid file or 0 if the pid file does not exist or is empty.
Writes the current process id to the pid file. Returns true on success, false if the pid file exists and contains a running process id or if unable to atomically write the pid file out.
Truncates the pid file and then unlinks it.
Attempts to write the current process id to the pid file and returns a Guard that will truncate and unlink the pid file if it goes out of scope.
{ my $lock = $pidfile->lock; run_service; } # $lock goes out of scope and pid file is truncated and unlinked
Jeff Ober <jeffober@gmail.com>
This software is copyright (c) 2017 by Jeff Ober.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Proc::tored, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Proc::tored
CPAN shell
perl -MCPAN -e shell install Proc::tored
For more information on module installation, please visit the detailed CPAN module installation guide.