#!/bin/sh
##############################################################
#
#  off - script to kill all processes with specified name
#
##############################################################
###########################################
# displays the usage information
###########################################
usage() {
	echo "$1 usage : $1 process_name";
	exit
}

###########################################
# kills all processes with name $1
###########################################
kill_procs()
{
	case `uname -s` in
		Darwin*)
			PSARGS="-xo pid,command";;
		SunOS*)
			PSARGS="-aeo pid,comm";;
		Linux*)
			PSARGS="xo pid,comm";;
		*)
			PSARGS="-xo pid,comm";;
	esac
	
	proc_name=$1
	number_of_procs=`ps $PSARGS | grep -v $0 | grep -v grep | grep $proc_name | wc -l`
	pid_list=`ps $PSARGS | grep -v grep | grep -v $0 | grep $proc_name | awk '{print $1}'`
	printf "There are %d %s processes:\n" $number_of_procs $proc_name 

	for i in $pid_list ; do
		echo "Killing process $i"
		kill $i
	done
	echo ""
}

############################################
# main script

case $# in
0)	usage $0 ;;
*) 	kill_procs $1;;
esac

