The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Piddy - Easy Linux PID Management

DESCRIPTION

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.

SYNOPSIS

    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"; }

new

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'});

info

Reads information on the process from /proc

    my $state = $pid->info('state'); # Piddy formats state to make it look nicer, too!

suspend

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);

continue

Resumes a stopped process.

    $pid->continue(5367);

kill

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);

ppid

Returns the parent process id

pid

Returns the pid of the current instance

running

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"; }

last_error

Returns the last known error

BUGS

Please e-mail bradh@cpan.org

AUTHOR

Brad Haywood <bradh@cpan.org>

COPYRIGHT & LICENSE

Copyright 2011 the above author(s).

This sofware is free software, and is licensed under the same terms as perl itself.