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»
In reply to Better way to search in the process table? by karlgoethebier
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |