-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkill_process.sh
More file actions
executable file
·35 lines (26 loc) · 926 Bytes
/
kill_process.sh
File metadata and controls
executable file
·35 lines (26 loc) · 926 Bytes
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
#!/bin/bash
# kill-process.sh
NOPROCESS=2
process=xxxyyyzzz # Use nonexistent process.
# For demo purposes only...
# ... don't want to actually kill any actual process with this script.
#
# If, for example, you wanted to use this script to logoff the Internet,
# process=pppd
t=`pidof $process` # Find pid (process id) of $process.
# The pid is needed by 'kill' (can't 'kill' by program name).
if [ -z "$t" ] # If process not present, 'pidof' returns null.
then
echo "Process $process was not running."
echo "Nothing killed."
exit $NOPROCESS
fi
kill $t # May need 'kill -9' for stubborn process.
# Need a check here to see if process allowed itself to be killed.
# Perhaps another " t=`pidof $process` " or ...
# This entire script could be replaced by
# kill $(pidof -x process_name)
# or
# killall process_name
# but it would not be as instructive.
exit 0