my @results = `ps -ef`;
####
my @results = `ps -fu $user`;
####
#!/usr/bin/perl -w
use strict;
my $prog = (split "\/", $0)[-1];
die "Usage: $prog\n" if @ARGV;
my $user = getpwuid $<;
my @results = qx{/bin/ps -fu $user};
chomp @results;
shift @results; # remove header
my %listing;
for (@results) {
if (m|^([\w\d]+) \s+
(\d+) \s+
(\d+) \s+
(\d+) \s+
([\w\d:]+) \s+
([\w\d/?]+) \s+
([\w\d:]+) \s+
(.*)$|x) {
my $hashref;
$$hashref{'uid'} = $1;
$$hashref{'pid'} = $2;
$$hashref{'ppid'} = $3;
$$hashref{'c'} = $4;
$$hashref{'stime'} = $5;
$$hashref{'tty'} = $6;
$$hashref{'time'} = $7;
$$hashref{'cmd'} = $8;
$listing{$pid} = $hashref;
}
else {
warn "$prog: Could not process line! Line follows:\n$_\n";
next
}
}
my ($shell) = ($ENV{SHELL} =~ m{([^/]*)$}; # get the basename of the shell
my $pid = $$;
my $ppid = $listing{$pid}->{ppid};
while ($listing{$ppid}->{cmd} !~ m/$shell$/;) {
$pid = $ppid;
$ppid = $listing{$pid}->{ppid};
}
# $ppid should have the current shell's pid
for my $pid (keys %listing) {
kill 9, $pid
unless $listing{$pid}->{cmd} =~ m/^-/ and $pid != $ppid;
}