ActiveState::Unix::ProcInfo - Portable extraction of process info


 use ActiveState::Unix::ProcInfo qw(proc_info);
 my $info = proc_info(root_pid => $$);
 # examine $info
 for my $p (proc_info()) {
     print "$p->{pid} $p->{vsz} $p->{args}\n";


This module provides a single function called proc_info() that is a portable wrapper around the system's ps command. The function takes the following key/value arguments:

root_pid => $pid
root_pid => [$pid1, $pid2,...]

Only processes with the given PID (or PIDs) and their descendants are selected.

root_args_match => qr/.../

Only processes and their descendants who's command line matches the regular expression are selected.

Note that this might not match as expected on platforms where args is truncated, see the description of args below.

If no arguments are given, information about all processes on the system is returned.

In scalar context a hash reference is returned. The keys of this hash are the PIDs of the processes selected and the value is a hash with the following elements:


The PID of the parent of this process.


The size of the process in virtual memory in 1024 byte units.


The size of the process in physical memory in 1024 byte units.


The command with its arguments as a single string. The command and arguments are separated by space. The string might be truncated.

On Solaris it is truncated to the first 80 chars. On HP-UX it is truncated to the first 60 chars. On Linux the limit appears to be 4096.


The number of threads running in this process. This field might be missing for systems where the thread count can't be determined.


The number of direct children of this process.


The number of children + grand-children + grand-grand-children + ...

In list context a list of hash references are returned, each one representing a single process. The hash has the same fields as described above, plus a pid field.