2
# Copyright (C) 2000-2002, 2004 MySQL AB
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
# This is a utility for MySQL. It is not needed by any standard part
20
# Usage: mysql_zap [-signal] [-f] [-t] pattern
22
# Configuration parameters.
24
$sig = ""; # Default to try all signals
30
$BSD = -f '/vmunix' || $ENV{"OS"} eq "SunOS4" || $^O eq 'darwin';
31
$LINUX = $^O eq 'linux';
32
$pscmd = $BSD ? "/bin/ps -auxww" : $LINUX ? "/bin/ps axuw" : "/bin/ps -ef";
34
open(TTYIN, "</dev/tty") || die "can't read /dev/tty: $!";
35
open(TTYOUT, ">/dev/tty") || die "can't write /dev/tty: $!";
39
$SIG{'INT'} = 'cleanup';
41
while ($#ARGV >= $[ && $ARGV[0] =~ /^-/) {
42
if ($ARGV[0] =~ /(ZERO|HUP|INT|QUIT|ILL|TRAP|ABRT|EMT|FPE|KILL|BUS|SEGV|SYS|PIPE|ALRM|TERM|URG|STOP|TSTP|CONT|CLD|TTIN|TTOU|IO|XCPU|XFSZ|VTALRM|PROF|WINCH|LOST|USR1|USR2)/ || $ARGV[0] =~ /-(\d+)$/) {
44
} elsif ($ARGV[0] eq "-f") {
46
} elsif ($ARGV[0] eq "-t") {
50
elsif ($ARGV[0] eq "-a")
54
elsif ($ARGV[0] eq "-?" || $ARGV[0] eq "-I" || $ARGV[0] eq "--help")
59
print STDERR "$0: illegal argument $ARGV[0] ignored\n";
69
system "stty cbreak </dev/tty >/dev/tty 2>&1";
72
system "stty", 'cbreak',
73
system "stty", 'eol', '^A';
77
open(PS, "$pscmd|") || die "can't run $pscmd: $!";
81
# Catch any errors with eval. A bad pattern, for instance.
83
process: while ($cand = <PS>)
86
($user, $pid) = split(' ', $cand);
89
if ($opt_a) { $found = 1; }
94
if (! ($cand =~ $pat))
101
$found = 1 if $cand =~ $pat;
105
if (! $opt_f && ! $opt_t)
107
print TTYOUT "$cand? ";
108
read(TTYIN, $ans, 1);
109
print TTYOUT "\n" if ($ans ne "\n");
113
print TTYOUT "$cand\n";
115
if ($ans =~ /^y/i) { &killpid($sig, $pid); }
116
if ($ans =~ /^q/i) { last; }
125
Usage: $0 [-signal] [-?Ift] [--help] pattern
126
Options: -I or -? "info" -f "force" -t "test".
129
Kill processes that match the pattern.
130
If -f isn't given, ask user for confirmation for each process to kill.
131
If signal isn't given, try first with signal 15, then with signal 9.
132
If -t is given, the processes are only shown on stdout.
139
system "stty -cbreak </dev/tty >/dev/tty 2>&1";
142
system "stty", 'icanon';
143
system "stty", 'eol', '^@';
150
local($signal,$pid) = @_;
161
return if kill(0, $pid) == 0;
167
return if kill(0, $pid) == 0;
169
print "$pid will not die!\n";