#!/usr/bin/perl -w use strict; my $prog = (split "\/", $0)[-1]; die "Usage: $prog\n" if @ARGV; my $user = getpwuid $<; my @results = `ps -ef`; 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; push @listing, $hashref; } else { warn "$prog: Could not process line! Line follows:\n$_\n"; next } } # My thinking: when run from the shell, this process' ppid will be the # pid of my shell. Problem is, what happens when it's not run from the # shell (say, run through vi's ":!killclone")? my $ppid = (grep {$$_{'pid'} eq $$} @listing)[0]->{'ppid'}; @listing = grep {$$_{'uid'} eq $user} @listing; # Just mine @listing = grep {$$_{'cmd'} =~ /^-/} @listing; # Just login shells @listing = grep {$$_{'pid'} ne $ppid} @listing; # Not this shell for (@listing) { kill 9, $$_{'pid'} }