2
# kill-byname.sh: Killing processes by name.
3
# Compare this script with kill-process.sh.
6
#+ try "./kill-byname.sh xterm" --
7
#+ and watch all the xterms on your desktop disappear.
11
# This is a fairly dangerous script.
12
# Running it carelessly (especially as root)
13
#+ can cause data loss and other undesirable effects.
17
if test -z "$1" # No command-line arg supplied?
19
echo "Usage: `basename $0` Process(es)_to_kill"
25
ps ax | grep "$PROCESS_NAME" | awk '{print $1}' | xargs -i kill {} 2&>/dev/null
28
# ---------------------------------------------------------------
30
# -i is the "replace strings" option to xargs.
31
# The curly brackets are the placeholder for the replacement.
32
# 2&>/dev/null suppresses unwanted error messages.
34
# Can grep "$PROCESS_NAME" be replaced by pidof "$PROCESS_NAME"?
35
# ---------------------------------------------------------------
39
# The "killall" command has the same effect as this script,
40
#+ but using it is not quite as educational.