Ilya Zakharevich


OS2::Proc - Perl extension for get information about running processes and loaded modules.


  use OS2::Proc;
  $p_info = (proc_info($$,1))[0]->[0];
  $p_info->{pid} == $$ or die;
  $t_info = $p_info->{threads}[0];
  $ticks = ($t_info->{usertime}+$t_info->{systime});
  %i = OS2::SysInfo;
  $cpu_time = $ticks*$i{TIMER_INTERVAL}/10000;


This module access internal tables keeping information of OS/2 processes. The corresponding API call was present for a long time, but is documented only around OS/2 v4.5. Since older version are stable now, it should be safe to use this call (with certain limitations) for any version of OS/2.

Keep in mind that due to certain bugs in the OS/2 kernel some calls to this API may kill your system. E.g., it is not safe to get an info about non-existing PID until W3fp18. (The module contains a safeguard against this bug.)

This module allows querying the following data:

$href = global_info()

hash reference with sizes of internal tables for modules, procs, threads.

  print "$_ => $href->{$_}\n" for qw(modules procs threads);
$href_modules = mod_info()

$href_modules indexes modules by their handles, the value being a hash reference with the following fields:

  cnt_static     - No. of modules linked in at compile time
  name           - Full path name (except for SYSINIT/basedevs?)
  segcnt         - ?? Number of segments?
  static_handles - array reference with handles of modules linked
                        at compile time
  static_names   - same with names
  type           - ?? SYSINIT/IFS/DMD/SYS=0, DLL/EXE=1, 
($aref_processes, $href_modules) = proc_info(0)

information about all processes and modules on the system. Each entry referenced by $aref_processes is a hash reference with the following fields:

  threads         - Array of hash references with thread information
  pid             - pid
  ppid            - parent pid
  proc_type       - FullScreen/RealMode/VIO/PM/Detached
  type            - 0..4 (see proc_type)
  status_array    - combination of ExitList/ExitingT1/Exiting/
  state           - combination of flags in 0x01..0x80 (see status_array)
  sessid          - SessionId
  module_name     - full name of the executabale (!)
  module_handle   - module handle of the executable
  threadcnt       - No. of threads
  privsem32cnt    - No. of private 32bit semaphores
  sem16cnt        - No. of 16bit semaphores
  dllcnt          - length
  shrmemcnt       - No. of shared memory segments
  fdscnt          - No. of available file descriptors
  dynamic_names   - reference to array with full names of
                        runtime-loaded modules (!)
  dynamic_handles - same with handles
  static_handles  - array reference with handles of modules linked
                        at compile time (!)
  static_names    - same with names (!)

Each thread-information hash has the following entries

  priority       - absolute priority (?)
  priority_class - Idle-Time/Regular/Time-Critical/Fixed-High
  priority_level - Priority shift inside class (larger is higher)
  sleepid        - ???
  slotid         - "Global" thread id
  state          - 1,2,5 (see thread_state)
  systime        - Cumulative no. of busy ticks spent in syscalls
  thread_state   - Ready/Blocked/Running
  threadid       - Thread Id "in the process"
  usertime       - Cumulative no. of busy ticks spent in user code

Keep in mind that the semantic of priority_class is not monotonic, monotonic is Idle-Time/Regular/Fixed-High/Time-Critical.

The $href_modules is the same as for mod_info().

$aref = proc_info()

same info with processes restricted to the current process, and modules to modules used by the current process.

$aref = proc_info($pid)

same about a given ProcessID.

$aref = proc_info($pid,$flags)

Allows restriction of the information restricted to one about

  processes     - 0x001
  modules       - 0x002
  semaphores    - 0x004
  shared memory - 0x008
  files         - 0x100

and without any parsing. The description above corresponds to $flags==3. Only the combinations of 0x1 and 0x2 are allowed now. If 0x2 is not present, the fields marked with (!) are omited from the process list descriptions.

$href = process_info($pid)

Gives a reference to a hash with process information as above, except for those marked with (!).


Ilya Zakharevich <>



Hosting generously
sponsored by Bytemark