Kill via Cron...
Karl Vogel
vogelke at hcst.com
Tue Apr 20 18:58:19 UTC 2010
>> On Tue, 20 Apr 2010 08:52:58 +0100,
>> "mcoyles" <mcoyles at horbury.wakefield.sch.uk> said:
M> kill -9 `ps ax | grep backup | grep -v grep | awk '{print $1}'`
I've typed "ps ax | grep something | grep -v grep" often enough to
automate it. The "psax" script below accepts an optional egrep-style
regex and displays only the matching processes.
You can make your life easier by using process groups more often.
For example, in the comments below there are four separate httpd
processes in the same process group. If I wanted to kill them all,
I could send HUP to PGID 198 instead of using four kill commands.
There's a perl version of "kill" included in Perl power tools. I made
some minor changes to use process groups instead:
http://www.pobox.com/~vogelke/src/toolbox/perl/killpg.txt
--
Karl Vogel I don't speak for the USAF or my company
Son, looks to me like you're spending too much time on one subject.
--Shelby Metcalf, basketball coach at Texas A&M,
to a player who received four F's and one D
---------------------------------------------------------------------------
#!/bin/sh
#<psax: runs "ps", looks for an optional egrep regex (BSD version).
#
# me% psax 'super|http'
# USER PID PPID PGID RSZ TT STARTED TIME COMMAND
# root 198 1 198 1384 ?? 11Jul09 7:53.76 /path/to/httpd -DSSL
# www 252 198 198 1976 ?? 11Jul09 0:44.96 /path/to/httpd -DSSL
# www 253 198 198 1992 ?? 11Jul09 0:47.81 /path/to/httpd -DSSL
# www 54291 198 198 1992 ?? 13Jul09 0:47.78 /path/to/httpd -DSSL
# root 92729 204 8 304 ?? 25Feb10 0:01.25 supervise qmail-send
# root 92730 204 8 300 ?? 25Feb10 0:01.40 supervise log
# root 92731 204 8 304 ?? 25Feb10 0:01.04 supervise qmail-smtpd
# root 92732 204 8 300 ?? 25Feb10 0:01.16 supervise log
PATH=/bin:/usr/sbin:/usr/bin:/usr/local/bin
export PATH
umask 022
# Solaris: ps -cef -o user,pid,pgid,class,pri,rss,time,args
# Linux: ps ax -o user,pid,pgid,rss,start,bsdtime,args
cmd="ps -axw -o user,pid,ppid,pgid,rsz,tt,start,time,command"
case "$#" in
0) exec $cmd ;;
*) exec $cmd | egrep "COMMAND|$*" | egrep -v "egrep|/bin/sh $0" ;;
esac
exit 0
More information about the freebsd-questions
mailing list