home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: news.software.b,comp.lang.perl,alt.sources
- From: vixie@decwrl.dec.com (Paul Vixie)
- Subject: C news lock file summary in Perl for BSD
- Message-ID: <1990May17.184417.5553@decwrl.dec.com>
- Date: Thu, 17 May 90 18:44:17 GMT
-
- #! /usr/local/bin/perl
-
- $: .= '/';
-
- for (split(/\n/, `ps alx`)) {
- next if (/^ /); # header
- if (/(.......)(....)(......)(......)/) {
- ($pid, $ppid) = (0+$3, 0+$4);
- $children{$ppid} .= "$pid ";
- }
- }
-
- chdir("/usr/lib/news") || die "/usr/lib/news";
-
- for (<LOCK*>) {
- next if (/^LOCKTM/);
- chop ($pid = `cat $_`);
- s/^LOCK//;
- s/^$/(main)/;
- &ps_u($pid, $_);
- }
-
- exit 0;
-
- format top =
- (lock) USER PID %CPU %MEM SZ RSS TT STAT TIME COMMAND
- .
- format STDOUT =
- @<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<
- $lock, $part1, $command
- ~ ^<<<<<<<<<<<<<<<<<<<<<
- $command
- .
-
- sub ps_u {
- local($pid, $lock) = @_;
- local($header, $_) = split(/\n/, `ps uww$pid`);
-
- return if (!$pid);
- # vixie 19201 14.0 0.4 409 306 r9 R 0:00 (ps)
- # aaaaaaaaabbbbbcccccdddddeeeeefffffggghhiiiiiiiii
- /(.................................................)(.*)/;
- ($part1, $command) = ($1, $2);
- write;
- ## print "children are: ".$children{$pid}."\n";
- for (split(/ /, $children{$pid})) {
- ## print "descending to $_ from $pid\n";
- &ps_u($_, " ");
- }
- }
-