[svn:p5ee] r9387 - p5ee/trunk/App-Context/lib/App

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Mon Apr  9 11:38:37 2007
New Revision: 9387

Modified:
   p5ee/trunk/App-Context/lib/App/Context.pm

Log:
add get_proc_info() [Linux only right now]

Modified: p5ee/trunk/App-Context/lib/App/Context.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context.pm	(original)
+++ p5ee/trunk/App-Context/lib/App/Context.pm	Mon Apr  9 11:38:37 2007
@@ -2585,5 +2585,56 @@
     return($info);
 }
 
+# /proc/$$/status
+# Name:   ksh
+# State:  S (sleeping)
+# Tgid:   29147
+# Pid:    29147
+# PPid:   29146
+# TracerPid:      0
+# Uid:    102     102     102     102
+# Gid:    205     205     205     205
+# FDSize: 32
+# Groups: 205 201 202 214 3000 203 217
+# VmSize:     1624 kB
+# VmLck:         0 kB
+# VmRSS:       608 kB
+# VmData:      124 kB
+# VmStk:        12 kB
+# VmExe:       176 kB
+# VmLib:      1292 kB
+# SigPnd: 0000000000000000
+# SigBlk: 0000000000000000
+# SigIgn: 8000000000380000
+# SigCgt: 0000000000016007
+# CapInh: 0000000000000000
+# CapPrm: 0000000000000000
+# CapEff: 0000000000000000
+
+sub get_proc_info {
+    my ($self, @pids) = @_;
+    @pids = ($$) if ($#pids == -1);
+    my ($pid, $proc);
+    my $procs = {};
+    foreach $pid (@pids) {
+        $proc = {};
+        $procs->{$pid} = $proc;
+        # print "FILE: /proc/$$/status\n";
+        if (open(main::FILE, "/proc/$$/status")) {
+            while (<main::FILE>) {
+                if (/^Vm([A-Za-z]+):\s*([0-9]+)/) {
+                    $proc->{lc($1)} = $2;
+                }
+            }
+            close(main::FILE);
+            $proc->{text} = $proc->{exe} + $proc->{lib};
+        }
+        else {
+            $self->log("ERROR: Can't open /proc/$$/status: $!");
+        }
+    }
+    return($procs);
+}
+
 1;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.