Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!haven.umd.edu!uvaarpa!mmdf From: ted@evi.com (Ted Stefanik) Newsgroups: comp.lang.perl Subject: Scanning "ps" output with Perl Message-ID: <1991May3.162019.5613@uvaarpa.Virginia.EDU> Date: 3 May 91 16:20:19 GMT Sender: mmdf@uvaarpa.Virginia.EDU (Uvaarpa Mail System) Reply-To: ted@evi.com (Ted Stefanik) Organization: The Internet Lines: 38 I've noticed that several Perl utilities scan "ps" output using splits and/or regular expressions. I'd like to add some cautions to these approaches. When a particular process's statistics numbers get too big for the column space alloted to that number, ps just slams the number into the preceeding column. For example, this looks nice: USER PID %CPU %MEM SZ RSS TT STAT TIME COMMAND ted 18374 51.2 3.0 488 380 p0 R 0:00 ps auxww If the process got memory hoggy and CPU hoggy, and was niced and not currently active, you'd get: USER PID %CPU %MEM SZ RSS TT STAT TIME COMMAND ted 18374 51.2 3.012488 1380 p0 IWN2345:45 ps auxww Notice that the size and time fields blend into the previous fields. In my opinion, splitting is out. You have to be very careful with regular expressions, because the white space is not always gauranteed to be there. I use substr, but that would also fail if the fields overflow one more place: USER PID %CPU %MEM SZ RSS TT STAT TIME COMMAND ted 18374 51.2 3.0124888 1380 p0 IWN12345:45 ps auxww (Although I both these are unlikely on my machine - 65MB swap space with weekly reboots.) ************************************************************************* * Ted Stefanik (Electronic Component Information Systems) * * Expert Views * * 100 Fifth Avenue ted@evi.com * * Waltham, MA 02154 ted%evi.com@uu.psi.com * * (617) 890-0333 uupsi!blt!ted * *************************************************************************