1Proc::ProcessTable(3) User Contributed Perl DocumentationProc::ProcessTable(3)
2
3
4
6 Proc::ProcessTable - Perl extension to access the unix process table
7
9 use Proc::ProcessTable;
10
11 my $p = Proc::ProcessTable->new( 'cache_ttys' => 1 );
12 my @fields = $p->fields;
13 my $ref = $p->table;
14
16 Perl interface to the unix process table.
17
19 new Creates a new ProcessTable object. The constructor can take the
20 following flags:
21
22 enable_ttys -- causes the constructor to use the tty determination
23 code, which is the default behavior. Setting this to 0 disables
24 this code, thus preventing the module from traversing the device
25 tree, which on some systems, can be quite large and/or contain
26 invalid device paths (for example, Solaris does not clean up
27 invalid device entries when disks are swapped). If this is
28 specified with cache_ttys, a warning is generated and the
29 cache_ttys is overridden to be false.
30
31 cache_ttys -- causes the constructor to look for and use a file
32 that caches a mapping of tty names to device numbers, and to create
33 the file if it doesn't exist. This feature requires the Storable
34 module. By default, the cache file name consists of a prefix
35 /tmp/TTYDEVS_ and a byte order tag. The file name can be accessed
36 (and changed) via $Proc::ProcessTable::TTYDEVSFILE.
37
38 fields
39 Returns a list of the field names supported by the module on the
40 current architecture.
41
42 table
43 Reads the process table and returns a reference to an array of
44 Proc::ProcessTable::Process objects. Attributes of a process object
45 are returned by accessors named for the attribute; for example, to
46 get the uid of a process just do:
47
48 $process->uid
49
50 The priority and pgrp methods also allow values to be set, since
51 these are supported directly by internal perl functions.
52
54 # A cheap and sleazy version of ps
55 use Proc::ProcessTable;
56
57 my $FORMAT = "%-6s %-10s %-8s %-24s %s\n";
58 my $t = Proc::ProcessTable->new;
59 printf($FORMAT, "PID", "TTY", "STAT", "START", "COMMAND");
60 foreach my $p ( @{$t->table} ){
61 printf($FORMAT,
62 $p->pid,
63 $p->ttydev,
64 $p->state,
65 scalar(localtime($p->start)),
66 $p->cmndline);
67 }
68
69
70 # Dump all the information in the current process table
71 use Proc::ProcessTable;
72
73 my $t = Proc::ProcessTable->new;
74
75 foreach my $p (@{$t->table}) {
76 print "--------------------------------\n";
77 foreach my $f ($t->fields){
78 print $f, ": ", $p->{$f}, "\n";
79 }
80 }
81
83 Please see the file README in the distribution for a list of supported
84 operating systems. Please see the file PORTING for information on how
85 to help make this work on your OS.
86
88 D. Urist, durist@frii.com
89
91 Proc::ProcessTable::Process, perl(1).
92
93
94
95perl v5.34.0 2022-01-21 Proc::ProcessTable(3)