File: kall

package info (click to toggle)
remind 03.00.19-2
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 1,452 kB
  • ctags: 1,712
  • sloc: ansic: 14,190; sh: 2,496; perl: 314; makefile: 165; csh: 14
file content (42 lines) | stat: -rw-r--r-- 926 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh
#
# $Id: kall,v 1.1 1998/01/15 02:50:20 dfs Exp $
#
# kall - kill all processes belonging to this user that match
#           specified string.

signal=`echo $1 | grep '^\-.*'`
me=`basename $0`

if [ "$signal" != "" ]; then
	shift
else
	signal="-TERM"
fi

if [ "$1" = "" ]; then
	echo "usage: $me [-signal] string [string...]"
	echo "       kills all of your processes where command name matches"
	echo "       any of the given strings."
	exit
fi

msg="0"

while [ "$1" != "" ]; do

# NOTE:  You may have to modify the next line, since PS is non-portable.
# The 'awk' command picks out the process IDs to pass them on to kill.
	rprocs=`ps cx | awk '{if(prog == $NF && $1 != mypid) print $1}' prog=$1 mypid=$$ -`
	if [ "$rprocs" != "" ]; then
		msg="1"
		echo -n "${me}: Sending $signal signal to $1 process(es)"
		echo '...'
		kill $signal $rprocs
	fi
	shift
done

if [ $msg = "1" ]; then
    echo "${me}: Done."
fi