Find related processes with a Perl script

Jul 04, '03 12:27:00PM

Contributed by: hmelton

I wrote a Perl script I call psmonitor long ago to massage the output of the ps command into a list that tells the parent processes of a searched-for program. I have placed the code (as well as some of my other simple scripts) on my website for easy access.

Here's some sample output:

% psmonitor mysql
  ---------------------------------------
  root 11159 0:00.00 con- 0.0 (mysql)
  ---------------------------------------
  hmelton 11204 0:00.02 p2 6.0 ./bin/mysql -e insert into status
     values(53,"7"); writing
  hmelton 11158 0:00.07 p2 0.4 perl -w /Users/hmelton/bin/mkstatus
  hmelton 11157 0:00.01 p2 0.0 perl -w /Users/hmelton/bin/status
  hmelton 11156 0:00.04 p2 0.0 -tcsh (tcsh)
  hmelton 11029 0:12.15 ?? 6.9 /Applications/Utilities/Terminal.app/
     Contents/MacOS/Terminal -psn_0_79953921
  hmelton 176 73:25.55 ?? 0.3 /System/Library/CoreServices/
     WindowServer -daemon
  root 1 0:00.06 ?? 0.0 /sbin/init
  ---------------------------------------
  mysql 362 0:00.44 ?? 0.0 /usr/local/mysql-3.23.51/bin/mysqld
  root 338 0:00.06 ?? 0.0 sh ./bin/safe_mysqld
  root 1 0:00.06 ?? 0.0 /sbin/init
[robg adds: I broke some of the output lines for a narrower display width...]

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030627015227674