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 }