home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1347 < prev    next >
Encoding:
Text File  |  1990-12-28  |  1.4 KB  |  57 lines

  1. Newsgroups: news.software.b,comp.lang.perl,alt.sources
  2. From: vixie@decwrl.dec.com (Paul Vixie)
  3. Subject: C news lock file summary in Perl for BSD
  4. Message-ID: <1990May17.184417.5553@decwrl.dec.com>
  5. Date: Thu, 17 May 90 18:44:17 GMT
  6.  
  7. #! /usr/local/bin/perl
  8.  
  9. $: .= '/';
  10.  
  11. for (split(/\n/, `ps alx`)) {
  12.     next if (/^ /);                    # header
  13.     if (/(.......)(....)(......)(......)/) {
  14.         ($pid, $ppid) = (0+$3, 0+$4);
  15.         $children{$ppid} .= "$pid ";
  16.     }
  17. }
  18.  
  19. chdir("/usr/lib/news") || die "/usr/lib/news";
  20.  
  21. for (<LOCK*>) {
  22.     next if (/^LOCKTM/);
  23.     chop ($pid = `cat $_`);
  24.     s/^LOCK//;
  25.     s/^$/(main)/;
  26.     &ps_u($pid, $_);
  27. }
  28.  
  29. exit 0;
  30.  
  31. format top =
  32. (lock)  USER       PID %CPU %MEM   SZ  RSS TT STAT  TIME COMMAND
  33. .
  34. format STDOUT =
  35. @<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<
  36. $lock,  $part1,                                          $command
  37. ~                                                        ^<<<<<<<<<<<<<<<<<<<<<
  38.                                                          $command
  39. .
  40.  
  41. sub ps_u {
  42.     local($pid, $lock) = @_;
  43.     local($header, $_) = split(/\n/, `ps uww$pid`);
  44.  
  45.     return if (!$pid);
  46.     # vixie    19201 14.0  0.4  409  306 r9 R     0:00  (ps)
  47.     # aaaaaaaaabbbbbcccccdddddeeeeefffffggghhiiiiiiiii
  48.     /(.................................................)(.*)/;
  49.     ($part1, $command) = ($1, $2);
  50.     write;
  51. ##    print "children are: ".$children{$pid}."\n";
  52.     for (split(/ /, $children{$pid})) {
  53. ##        print "descending to $_ from $pid\n";
  54.         &ps_u($_, " ");
  55.     }
  56. }
  57.