Style question - how to kill process based on user name / tty?

gwyn at BRL-VLD.ARPA gwyn at BRL-VLD.ARPA
Wed Aug 15 05:09:34 AEST 1984


From:      Doug Gwyn (VLD/VMB) <gwyn at BRL-VLD.ARPA>

Let the users kill off their own bloody processes.  UNIX is not
supposed to require operators.  I use the following scripts which are
based on versions from Kernighan & Pike:

#!/bin/sh
#	zap -- kill all processes matching pattern
#	adapted from Kernighan & Pike

#	last edit:	84/05/19	D A Gwyn
#	SCCS ID:	@(#)zap.sh	1.1

PATH=/usr/5bin:/bin:/usr/bin
HEAD=/vld/bin/head
PICK=/vld/bin/pick
IFS='
'

sig=
case $1 in
"")	echo 'Usage: zap [-2] pattern' 1>&2; exit 1;;
-*)	sig=$1; shift;;
esac

ps -ag | $HEAD 1

if pdp11
then	exec kill $sig `$PICK \`ps -ag | egrep "$*" | egrep -v 'zap|egrep'\` | awk '{print $2}'`
else	exec kill $sig `$PICK \`ps -ag | egrep "$*" | egrep -v 'zap|egrep'\` | awk '{print $1}'`
fi

#!/bin/sh
#	head -- print first few lines of file

#	last edit:	84/05/19	D A Gwyn
#	SCCS ID:	@(#)head.sh	1.1

PATH=/usr/5bin:/bin:/usr/bin

if [ $# -eq 0 ]
then	n=10
else	case $1 in
	[0-9]*)	n=$1;	shift;;
	*)	n=10;;
	esac
fi

exec sed -e ${n}q $*

#!/bin/sh
#	pick -- select arguments
#	adapted from Kernighan & Pike; to be replaced some day by C version

#	last edit:	84/05/19	D A Gwyn
#	SCCS ID:	@(#)pick.sh	1.1

PATH=/usr/5bin:/bin:/usr/bin

for i
do	echo "$i? \c" > /dev/tty
	read response
	case $response in
	[yY]*)	echo $i;;
	[qQ]*)	break;;
	esac
done < /dev/tty



More information about the Comp.unix.wizards mailing list