From owner-freebsd-stable Sat May 27 9:10:45 2000 Delivered-To: freebsd-stable@freebsd.org Received: from point.osg.gov.bc.ca (point.osg.gov.bc.ca [142.32.102.44]) by hub.freebsd.org (Postfix) with ESMTP id D548B37BECA; Sat, 27 May 2000 09:10:35 -0700 (PDT) (envelope-from Cy.Schubert@uumail.gov.bc.ca) Received: (from daemon@localhost) by point.osg.gov.bc.ca (8.8.7/8.8.8) id JAA09743; Sat, 27 May 2000 09:09:55 -0700 Received: from passer.osg.gov.bc.ca(142.32.110.29) via SMTP by point.osg.gov.bc.ca, id smtpda09741; Sat May 27 09:09:55 2000 Received: (from uucp@localhost) by passer.osg.gov.bc.ca (8.9.3/8.9.1) id JAA42417; Sat, 27 May 2000 09:09:54 -0700 (PDT) Received: from cwsys9.cwsent.com(10.2.2.1), claiming to be "cwsys.cwsent.com" via SMTP by passer9.cwsent.com, id smtpdR42413; Sat May 27 09:09:38 2000 Received: (from uucp@localhost) by cwsys.cwsent.com (8.10.1/8.9.1) id e4RG9cA94703; Sat, 27 May 2000 09:09:38 -0700 (PDT) Message-Id: <200005271609.e4RG9cA94703@cwsys.cwsent.com> Received: from localhost.cwsent.com(127.0.0.1), claiming to be "cwsys" via SMTP by localhost.cwsent.com, id smtpdF94685; Sat May 27 09:09:06 2000 X-Mailer: exmh version 2.1.1 10/15/1999 Reply-To: Cy Schubert - ITSD Open Systems Group From: Cy Schubert - ITSD Open Systems Group X-OS: FreeBSD 4.0-STABLE X-Sender: cy To: Brian Somers Cc: John Baldwin , Randall Hopper , stable@FreeBSD.ORG, housley@thehousleys.net, brian@hak.lan.Awfulhak.org Subject: Re: killall question In-reply-to: Your message of "Sat, 27 May 2000 16:46:26 BST." <200005271546.QAA64909@hak.lan.Awfulhak.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 27 May 2000 09:09:06 -0700 Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In message <200005271546.QAA64909@hak.lan.Awfulhak.org>, Brian Somers writes: > > > > On 27-May-00 Randall Hopper wrote: > > > housley@thehousleys.net: > > > |Randall Hopper said: > > > | > > > |> I have a script I run named "newroot". I want to kill it with killal > l. > > > |> > > > |> > ps -ax | grep newroot > > > |> 842 1 rhh /bin/sh /home/rhh/bin/newroot 360 > > > |> > > > |You will have to do something like > > > | > > > |kill `ps -ax | grep newroot | sed -e '^[0-9]*'` > > > > > > Ok. I thought I'd at least try to use the system version, but sounds lik > e > > > it's just not as flexible as killall's on other systems. > > > > > > Here's the shell script I settled on to override the default /usr/bin/kil > lall: > > > > > > ps -x | grep "$1" | egrep -v "grep|$0" | awk '{print $1;}' > > > > % killall grep > > # killall grepscript > > There are bad sub-string implications there too.... Here's a killall script I picked up from somewhere about 6-7 years ago (author unknown). I won't take credit for writing it, though I have modified it a little. The advantage over the FreeBSD and Linux killall is that it's portable to any platform. I've been using a version of this script for over 6 years on Solaris to kill a an application that won't clean up after itself properly. #!/usr/bin/perl # Usage: zap [-signal] pattern # Configuration parameters. $ENV{'PATH'}='/usr/bin:/bin:/usr/local/bin:/usr/sbin:/sbin'; $sig = 'TERM'; $BSD = -f '/vmunix' || -f '/kernel'; $pscmd = $BSD ? "ps -auxww" : "ps -ef"; $IA = 0; $IA = 1 if ( $0 !~ /zapall/ ); $QUIET = 0; if ($IA) { open(TTYIN, "/dev/tty") || die "can't write /dev/tty: $!"; select(TTYOUT); $| = 1; select(STDOUT); $SIG{'INT'} = 'cleanup'; } if ($#ARGV >= $[ && $ARGV[0] =~ /^-/) { if ($ARGV[0] =~ /-q$/ || $ARGV[0] =~ /-quiet$/) { $QUIET = 1; } elsif ($ARGV[0] =~ /-(\w+)$/) { $sig = $1; } else { print STDERR "$0: illegal argument $ARGV[0] ignored\n"; } shift; } if ($IA) { if ($BSD) { system "stty cbreak /dev/tty 2>&1"; } else { system "stty", 'cbreak', system "stty", 'eol', '^A'; } } open(PS, "$pscmd|") || die "can't run $pscmd: $!"; $title = ; if ($IA) { print TTYOUT $title; } # Catch any errors with eval. A bad pattern, for instance. eval <<'EOF'; while ($cand = ) { chop($cand); ($user, $pid) = split(' ', $cand); next if $pid == $$; $found = !@ARGV; foreach $pat (@ARGV) { $found = 1 if $cand =~ $pat; } next if (!$found); if ($IA) { print TTYOUT "$cand ? "; read(TTYIN, $ans, 1); print TTYOUT "\n" if ($ans ne "\n"); if ($ans =~ /^y/i) { kill $sig, $pid; } if ($ans =~ /^q/i) { last; } } else { kill $sig, $pid; if ($QUIET != 1) { print "Sending signal $sig to PID $pid\n"; } } } EOF if ($IA) { &cleanup; } sub cleanup { if ($BSD) { system "stty -cbreak /dev/tty 2>&1"; } else { system "stty", 'icanon'; system "stty", 'eol', '^@'; } print "\n"; exit; } Regards, Phone: (250)387-8437 Cy Schubert Fax: (250)387-5766 Team Leader, Sun/DEC Team Internet: Cy.Schubert@osg.gov.bc.ca Open Systems Group, ITSD, ISTA Province of BC To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message