#!/usr/bin/perl use strict; use warnings; use Proc::ProcessTable; use Data::Dump; my $processes = new Proc::ProcessTable; my $ancestry = 3; my %tree; my %all; for ( @{ $processes->table } ) { $all{ $_->pid } = $_; $tree{ $_->pid } = [$_] if $_->cmndline =~ /^\/usr\/sbin\/mysqld/; } # dd \%all; exit; # dd \%tree; exit; for my $child (keys %tree) { print qq(child:\t$child\n); my $ppid = $all{$child}->ppid; print qq(ppid:\t$ppid\n); for (1 .. $ancestry) { push @{$tree{$child}}, $all{$ppid}; $ppid = $all{$ppid}{ppid}; last unless $ppid; print qq(ppid:\t$ppid\n); } } dd \%tree; __END__