[padb] r312 committed - Strip leading whitespace from ps output before we split it on...

padb at googlecode.com padb at googlecode.com
Mon Nov 2 17:57:09 GMT 2009


Revision: 312
Author: apittman
Date: Mon Nov  2 09:55:58 2009
Log: Strip leading whitespace from ps output before we split it on
whitespace.  This ensures that the first column in the output is
returned as the first list element from the split call.

http://code.google.com/p/padb/source/detail?r=312

Modified:
  /trunk/src/padb

=======================================
--- /trunk/src/padb	Mon Nov  2 04:01:19 2009
+++ /trunk/src/padb	Mon Nov  2 09:55:58 2009
@@ -860,11 +860,14 @@
          my %procs;
          foreach my $proc (@procs) {

-            # A little bit of magic here, ps left pads its output with a
-            # space which the regexp matches so $pid is the second entry
-            # returned from the split command.  I need to verify that Linux
-            # ps and Solaris ps behave the same in this situation.
-            my ( undef, $pid, $ppid ) = split $SPACE, $proc;
+            # A little bit of magic here, ps sometimes left pads its
+            # output with a space which the regexp matches.  To avoid
+            # problems strip leadinging whitespace before we split so
+            # that $pid is the first entry returned from the split
+            # command.
+            $proc =~ s{\A$SPACE}
+	              {}x;
+            my ( $pid, $ppid ) = split $SPACE, $proc;
              $procs{$pid} = $ppid;
          }
          return %procs;




More information about the padb-devel mailing list