karlgoethebier has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, i need to search for some long running processes and their parents...
603 ? Ss 0:01 /usr/sbin/cron 18421 ? S 0:00 \_ /usr/sbin/cron 18423 ? Ss 0:00 | \_ /bin/sh /opt/pdi-jobs/4.3.0/CST/CE_Upload/CE_U +pload_MON.sh 18425 ? S 0:00 | \_ /bin/sh ./kitchen.sh -file=/opt/pdi-jobs/4 +.3.0/... 18444 ? Sl 1:47 | \_ java -Xmx512m -cp .:./lib/kettle-core. +jar...
...in this example the pids 18444, 18425, 18423 and 18421.
I thought to do it like this (scratch):
use Proc::ProcessTable; my $processes = new Proc::ProcessTable; my @java_processes = grep { $_->cmndline =~ /^\/System/ } @{ $processes->table }; # fake +pattern, got no java at home ;-) foreach my $java_process (@java_processes) { my $pid = $java_process->pid; # more stuff with this pid my $ppid = $java_process->ppid; my @parent = grep { $_->pid == $ppid } @{ $processes->table }; # more stuff with the parent my $gppid = $parent[0]->ppid; my @gparent = grep { $_->pid == $gppid } @{ $processes->table }; # more stuff with the grandparent my $ggppid = $gparent[0]->ppid; my @ggparent = grep { $_->pid == $ggppid } @{ $processes->table }; # more stuff with the great-grandparent }
Update: fixed typo: $ggppid.
I couldn't figure out something better yet.
Thank you very much for any hint and best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Better way to search in the process table?
by kcott (Archbishop) on Mar 02, 2014 at 22:29 UTC | |
by karlgoethebier (Abbot) on Mar 03, 2014 at 15:05 UTC | |
by kcott (Archbishop) on Mar 03, 2014 at 18:56 UTC | |
by karlgoethebier (Abbot) on Mar 04, 2014 at 12:05 UTC | |
by karlgoethebier (Abbot) on Mar 03, 2014 at 19:52 UTC | |
Re: Better way to search in the process table?
by hdb (Monsignor) on Mar 02, 2014 at 22:17 UTC | |
by karlgoethebier (Abbot) on Mar 03, 2014 at 15:15 UTC | |
Re: Better way to search in the process table?
by shmem (Chancellor) on Mar 02, 2014 at 22:04 UTC | |
by karlgoethebier (Abbot) on Mar 03, 2014 at 09:17 UTC |