From owner-freebsd-questions@FreeBSD.ORG Tue Apr 20 18:58:18 2010 Return-Path: <owner-freebsd-questions@FreeBSD.ORG> Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E353F106564A for <questions@freebsd.org>; Tue, 20 Apr 2010 18:58:18 +0000 (UTC) (envelope-from vogelke@hcst.com) Received: from beta.hcst.com (beta.hcst.com [192.52.183.241]) by mx1.freebsd.org (Postfix) with ESMTP id AA3958FC13 for <questions@freebsd.org>; Tue, 20 Apr 2010 18:58:18 +0000 (UTC) Received: from beta.hcst.com (localhost [127.0.0.1]) by beta.hcst.com (8.13.8/8.13.8/Debian-3) with ESMTP id o3KIfYUo018058 for <questions@freebsd.org>; Tue, 20 Apr 2010 14:41:34 -0400 Received: (from vogelke@localhost) by beta.hcst.com (8.13.8/8.13.8/Submit) id o3KIfXuF018057; Tue, 20 Apr 2010 14:41:33 -0400 From: Karl Vogel <vogelke@hcst.com> Received: by bsd118.wpafb.af.mil (Postfix, from userid 583) id C52D9BE09; Tue, 20 Apr 2010 14:38:59 -0400 (EDT) To: questions@freebsd.org In-reply-to: <002c01cae05e$7eab3ea0$7c01bbe0$@wakefield.sch.uk> (mcoyles@horbury.wakefield.sch.uk) Organization: Array Infotech X-Disclaimer: I don't speak for the USAF or Array Infotech. X-GPG-ID: 1024D/711752A0 2006-06-27 Karl Vogel <vogelke@pobox.com> X-GPG-Fingerprint: 56EB 6DBF 4224 C953 F417 CC99 4C7C 7D46 7117 52A0 References: <002c01cae05e$7eab3ea0$7c01bbe0$@wakefield.sch.uk> Message-Id: <20100420183859.C52D9BE09@bsd118.wpafb.af.mil> Date: Tue, 20 Apr 2010 14:38:59 -0400 (EDT) Cc: Subject: Re: Kill via Cron... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: vogelke+unix@pobox.com List-Id: User questions <freebsd-questions.freebsd.org> List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-questions>, <mailto:freebsd-questions-request@freebsd.org?subject=unsubscribe> List-Archive: <http://lists.freebsd.org/pipermail/freebsd-questions> List-Post: <mailto:freebsd-questions@freebsd.org> List-Help: <mailto:freebsd-questions-request@freebsd.org?subject=help> List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-questions>, <mailto:freebsd-questions-request@freebsd.org?subject=subscribe> X-List-Received-Date: Tue, 20 Apr 2010 18:58:19 -0000 >> On Tue, 20 Apr 2010 08:52:58 +0100, >> "mcoyles" <mcoyles@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