Grepping for a process (was Re: Killing process w/o number (csh))

Paul Davey pd at x.co.uk
Fri May 17 20:44:04 AEST 1991


In csh

	alias psg 'ps aux | sed -n -e "/sed -n -e /d\\
		/\!$/p\\
		/TIME COMMAND/p"'

(change 'ps aux' to 'ps -ef' for sysV.)

Converting to a ksh or sh function is left as an exercise for the
reader ...

To kill I use this script which I picked this up from the net some
time back.

#!/bin/sh
# slay :  kill processes by names 
#
# Do our best to locate the PIDs to kill from the give
# process names.
#

MYNAME=`basename $0`
Ask=yes
case $1 in
"")
	echo "Usage: $MYNAME process_name ..."
	exit 1 ;;
-n)
	Ask=no; shift ;;
esac

 # change 'ps aux' to 'ps -ef' for sysV.
PSAUX=`ps aux`
for pname
do
	line= PID=
	PID=`echo "$PSAUX" |
		grep -i $pname |
		awk '!/grep|'$MYNAME'/ {print $2}'`

	for pid in $PID
	do
		if [ $Ask = yes ]
		then
			line=`echo "$PSAUX" | awk '$2 == '$pid' {print}'`
			echo -n "Kill ($line)? "
			read reply
			case $reply in
			[Yy]*)	kill -9 $pid
				;;
			esac
		else
			kill -9 $pid
		fi
	done
done
 


--
 Regards,			 pd at x.co.uk          IXI Limited
	Paul Davey		 pd at ixi.uucp         62-74 Burleigh St.
				 ...!uunet!ixi!pd    Cambridge  U.K.
 "These are interesting times"   +44 223 462 131     CB1  1OJ      
				 USA: 1 800 XDESK 57



More information about the Comp.unix.shell mailing list