Unix::Process - Perl extension to get pid info from (/bin/ps).


Unix-Process documentation Contained in the Unix-Process distribution.

Index


Code Index:

NAME

Top

Unix::Process - Perl extension to get pid info from (/bin/ps).

SYNOPSIS

Top

  use Unix::Process;

    my $vsz = Unix::Process->vsz($$);
    my $pid = Unix::Process->pid;

DESCRIPTION

Top

All fields from the ps command can be fetched by calling a function of their name (see SYNOPSIS). If the pid is not given as an argument to the function, $$ (cur pid) is assumed.

This module is really just a giant AUTOLOAD to interact with the /bin/ps command. I suppose I could be talked into doing something real with it some day.

You can manually set the $Unix::Process::PS_PROGRAM = "/opt/bin/ps" by hand, or you can set $ENV{PS_PATH} = "/usr/local/bin/ps", but you must somehow instruct Unix::Process on the location of ps. Otherwise, it will guess "/bin/ps".

AUTHOR

Top

Paul Miller <jettero@cpan.org>

I am using this software in my own projects... If you find bugs, please please please let me know. :) Actually, let me know if you find it handy at all. Half the fun of releasing this stuff is knowing that people use it.

COPYRIGHT

Top

SEE ALSO

Top

perl(1), ps


Unix-Process documentation Contained in the Unix-Process distribution.

package Unix::Process;

use strict;
use warnings;
use Carp;
use IPC::System::Simple qw(capturex);

our $VERSION    = '1.3101';
our $PS_PROGRAM = $ENV{PS_PATH} || '/bin/ps';
our $AUTOLOAD;

1;

sub AUTOLOAD {
    die "unprocessable garbage: $AUTOLOAD" unless $AUTOLOAD =~ m/::(\w+)$/;
    my $sub = $1;

    my $f = sub {
        my $this = shift;
        my $pid  = shift; $pid = $$ unless $pid and int($pid);
        my $result = eval { capturex($PS_PROGRAM, '-o', $sub, '-p', $pid) };

        croak $@ if $@;

        return $1 if $result =~ m/[\r\n]\s*(.+?)\s*[\r\n]/ms;
        return;
    };

    {
        no strict 'refs';
        *{$AUTOLOAD} = $f;
    }
    goto &$f;
}

__END__
# Below is stub documentation for your module. You better edit it!