in reply to Re^2: Better way to search in the process table?
in thread Better way to search in the process table?

"If $ancestry == 3 and i don't say last unless $ppid, it goes back until PID 0 and sets one key in %tree to undef. I hope i didn't miss something."

The keys in %tree are unaffected by that statement: they're already set and you're looping through them (i.e. for my $child (keys %tree) {...}). You'll need to clarify this. You're probably referring to one of these: the value of the key (normally an arrayref); an element in that arrayref (normally a hashref); a key/value in one of those hashrefs.

I'd normally expect the parent of PID 0 to be PID 0 also. That's true for my OS but perhaps it's not the case on your OS. It's possible that Proc::ProcessTable does not return information for PID 0: I claim no particular experise with this module, you'll need to research this yourself. It could also be a security feature: maybe only UID 0 (root) can query PID 0.

If the code you currently have does what you want, perhaps just keep to the old adage: "If it ain't broke, don't fix it." :-)

-- Ken

Replies are listed 'Best First'.
Re^4: Better way to search in the process table?
by karlgoethebier (Abbot) on Mar 04, 2014 at 12:05 UTC
    "...they're already set"

    Yes. D'oh! I don't known why i wrote this nonsens :-(

    # output shortend $anchestry =3 ; # last unless $ppid; { 9675 => [ bless({ cmndline => "/usr/sbin/mysqld", pid => 9675, ppid => 9473, }, "Proc::ProcessTable::Process"), bless({ cmndline => "/bin/sh /usr/bin/mysqld_safe", pid => 9473, ppid => 1, }, "Proc::ProcessTable::Process"), bless({ cmndline => "init [3] ", pid => 1, ppid => 0, }, "Proc::ProcessTable::Process"), undef, <-- last slot ], } $anchestry = 3 ; last unless $ppid; { 9675 => [ bless({ cmndline => "/usr/sbin/mysqld", pid => 9675, ppid => 9473, }, "Proc::ProcessTable::Process"), bless({ cmndline => "/bin/sh /usr/bin/mysqld_safe", pid => 9473, ppid => 1, }, "Proc::ProcessTable::Process"), bless({ cmndline => "init [3] ", pid => 1, ppid => 0, }, "Proc::ProcessTable::Process"), ], # OK }

    It works.

    Thank you and best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Re^4: Better way to search in the process table?
by karlgoethebier (Abbot) on Mar 03, 2014 at 19:52 UTC

    I'll post tomorrow what i figured out because i don't have access to this machine tonight.

    Best regards and thank you, Karl

    «The Crux of the Biscuit is the Apostrophe»