killbyname and killpid (perl) (was Re: Killing the correct process)
Randal Schwartz
merlyn at iwarp.intel.com
Wed Feb 14 04:45:45 AEST 1990
In article <131696 at sun.Eng.Sun.COM>, rock%warp (Bill Petro (SunOS Marketing)) writes:
|
| I don't know if this is appropriate, but here is a handy little tool I
| use:
[tool deleted]
Well, here's a *couple* of tools I use to 'killbyname' and 'killpid'.
The first requires the second.
################################################## begin killbyname
#!/usr/bin/perl
$target = shift;
@pids = grep(s/^\S+\s+(\S+).*\s($target)$/$1/, split(/\n/,`ps uaxcww`));
exec 'killpid', @pids;
die "Cannot exec killpid ($!)";
################################################## end killbyname
################################################## begin killpid
#!/usr/bin/perl
for $a (@ARGV) {
print "killing $a...\n";
(print "$a already dead\n"), next unless kill 0, $a;
kill 1, $a;
sleep 1;
next unless kill 0, $a;
print "$a is stubborn, trying SIGKILL...\n";
kill 9, $a;
sleep 1;
next unless kill 0, $a;
print "$a won't die!\n";
}
################################################## end killpid
Usage is basically "killbyname sendmail" (to kill all sendmail
processes). "killpid" was invented because I was tired of typing
"kill 12345", waiting to see if it died, and then "kill -9 12345".
Just another Perl hacker,
--
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III |
| merlyn at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
More information about the Comp.unix.questions
mailing list