#!/usr/bin/perl -w # # file: checkp # purpose: checks whether either of parents of the current process # mathches the specified regexp # created: pasha aug 20 2005 # modified: pasha aug 26 2005 # modification: spelling in comments # pending: error handling # use strict; if (scalar @ARGV != 1) { print (STDERR "usage: $0 \n"); exit (-1); } # write process info to the hash my ($pid, $ppid, @rest); my %proc; # 'w' is for not trimming lines to 80 chars for (`ps -ef --no-headers w`) { (undef, $pid, $ppid, undef, undef, undef, undef, undef, @rest) = split (/\s+/, $_); $proc{$pid}{'ppid'} = $ppid; $proc{$pid}{'name'} = join (' ', @rest); } # search recursively for parent processes matching given regexp for ($pid = $$; $pid != 1; $pid = $proc{$pid}{'ppid'}) { exit (1) if ($proc{$pid}{'name'} =~ /$ARGV[0]/o); } exit (0); __END__