-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkillzombie.sh
executable file
·97 lines (89 loc) · 2.25 KB
/
killzombie.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
#===============================================================================
#
# FILE: killzombie.sh
#
# USAGE: ./killzombie.sh
#
# DESCRIPTION: kill zombie process periododically, a zombie is a dead one
# taking a PID but not with any process resources.
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Dexter H. Hu (), [email protected]
# COMPANY: HKU CS
# VERSION: 1.0
# CREATED: 03/10/2011 11:08:20 PM HKT
# REVISION: ---
#===============================================================================
#
# zombie_slayer [OPTIONS]
#
# -d
# Just diplay the zombie processes and exit
#
# -h | help
# Display help
#
# Default is to show processes and the ask what to kill
#
function Z_Display
{
echo ""
echo "PID - PPID - State - User - Proc"
UNIX95= ps -eo pid,ppid,state,user,comm | awk 'BEGIN { count=0 } $3 ~ /Z/ { count++; print $1,$2,$3,$4,$5 } END { print "\n" count " Zombie(s) to slay." }'
echo ""
}
function Z_Kill
{
read -p "Enter PPID to kill or 'exit' : " SLAY_PPID
if [ "$SLAY_PPID" = "exit" ] || [ "$SLAY_PPID" = "" ]
then
exit
fi
ps -p $SLAY_PPID | grep -q $SLAY_PPID
if [ $? -eq 0 ]
then
UNIX95= ps -o pid,user,state,comm -p $SLAY_PPID | \
awk '$1 ~ /^[0-9]*$/ { print "The program " $4 " with PID " $1 " is being run by the user " $2 " and is currently in state " $3 }'
read -p "Are you sure you want to kill PID $SLAY_PPID ? Y|N : " COMMIT_KILL
if [ "$COMMIT_KILL" = "Y" ] || [ "$COMMIT_KILL" = "y" ]
then
kill -9 $SLAY_PPID
echo ""
read -p "Killed PID $SLAY_PPID. Run again? Y/N : " GO_AGAIN
else
Z_Kill
fi
else
echo "Invalid PID. Try again."
echo ""
Z_Kill
fi
}
function help
{
echo "Usage: zombie_slayer [-h | help -d]"
echo "-d just display zombie processes and exit"
echo "-h | help : This help"
exit
}
if [ "$1" = "-h" ] || [ "$1" = "help" ]
then
help
fi
if [ "$1" = "-d" ]
then
Z_Display
else
Z_Display
Z_Kill
fi
if [ "$GO_AGAIN" = "Y" ] || [ "$GO_AGAIN" = "y" ]
then
Z_Display
Z_Kill
fi
echo ""