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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.