Piddy - Easy Linux PID Management
Manage the current process/pid and/or external ones (Not the current process) easily with this module. Use it to create helpful sysadmin scripts while it lets you control the flow of a process by suspending and resuming it at will. Some options require root access, but Piddy will let you know which ones when you try to run them. Piddy will even attempt to determine if the pid instance is actually running as a threaded process. This module probably still needs a lot of work, but it functions fine for the most part.
use Piddy; my $pid = Piddy->new({ pid => 5367, path => '/var/run/pids', }); if ($pid->running($pid->pid)) { $pid->suspend($pid->pid); # temporarily stop the process where it is print $pid->info('state') . "\n"; # read the current state of the process sleep 20; $pid->continue($pid->pid); # resume the process from where it was stopped } else { print "Oh.. " . $pid->pid . " is not actually running..\n"; }
Creates a new PID instance. There are a couple of options you can pass...
pid = Use an external PID (Not the current running process). path = Location of the pid file
# Use pid 5367 and save the pid file as /var/run/pids/5367.pid my $p = Piddy->new({pid => 5367, path => '/var/run/pids'});
Reads information on the process from /proc
my $state = $pid->info('state'); # Piddy formats state to make it look nicer, too!
Temporarily suspend a process (will not kill it, simply stops it exactly where it is so you can resume it later. Handy when writing scripts to monitor performance - you can stop the process then resume it when things have cooled down.
$pid->suspend(5367);
Resumes a stopped process.
$pid->continue(5367);
Uses the systems kill command instead of Perl's. If you simply want to -9 or -15 a process then use Perl, but for things like stopping/continuing processes, I could not get it to work any other way.
$pid->kill('-9', 5367); $pid->kill('-STOP', 5367); # or just use $pid->suspend(5367);
Returns the parent process id
Returns the pid of the current instance
Determines whether the current pid is running, or if you pass another pid as an argument it will check that instead. By default it will use /proc, otherwise it will revert to ps and grep.
if ($pid->running(5367)) { print "It's running!\n"; }
Returns the last known error
Please e-mail bradh@cpan.org
Brad Haywood <bradh@cpan.org>
Copyright 2011 the above author(s).
This sofware is free software, and is licensed under the same terms as perl itself.
To install Piddy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Piddy
CPAN shell
perl -MCPAN -e shell install Piddy
For more information on module installation, please visit the detailed CPAN module installation guide.