-
Notifications
You must be signed in to change notification settings - Fork 6
/
killm
executable file
·231 lines (214 loc) · 6.35 KB
/
killm
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
# shell script to remove all of my IPC keys
# Modified by Robert Martin to work on Mac 10.4, due to IPCS requiring sudo to list any
# shared memory usage, even if you own it; also modified using Jim Wyllie's "kill
# all related processes" idea
# Simplified by Shawn Ostermann in October, 2023 to remove Enhanced Regular Expressions, "grep -E", and "sed -E"
# to make it more portable (to Solaris in particular). Also quieted down the output a little.
ION_OPEN_SOURCE=1
OS_VERS=""
# Fix for SourceForge Bug #60, killm IPC cleanup fails for long account names
# Since ipcs truncates usernames to 10 characters, we need to match against a
# truncated username so we trim the username to 10 characters.
# NOTE: This may cause conflicts with long usernames with similar beginning
# characters. We'll look for a more robust solution in the near future.
USERNAME_CUT=`echo $USER | cut -c 1-10`
KILLPROCESSLIST="acsadmin lt-acsadmin \
acslist lt-acslist \
aoslsi lt-aoslsi \
aoslso lt-aoslso \
bibeadmin lt-bibeadmin \
bibeclo lt-bibeclo \
bpadmin lt-bpadmin \
bpcancel lt-bpcancel \
bpchat lt-bpchat \
bpclm lt-bpclm \
bpclock lt-bpclock \
bpcounter lt-bpcounter \
bpdriver lt-bpdriver \
bpecho lt-bpecho \
bping lt-bping \
bplist lt-bplist \
bpnmtest lt-bpnmtest \
bprecvfile lt-bprecvfile \
bpsecadmin lt-bpsecadmin \
bpsendfile lt-bpsendfile \
bpsink lt-bpsink \
bpsource lt-bpsource \
bpstats lt-bpstats \
bpstats2 lt-bpstats2 \
bptrace lt-bptrace \
bptransit lt-bptransit \
brsccla lt-brsccla \
brsscla lt-brsscla \
bsscounter lt-bsscounter \
bssdriver lt-bssdriver \
bsspadmin lt-bsspadmin \
bsspcli lt-bsspcli \
bsspclo lt-bsspclo \
bsspclock lt-bsspclock \
bssrecv lt-bssrecv \
bssStreamingApp lt-bssStreamingApp \
cgrfetch lt-cgrfetch \
cpsd lt-cpsd \
dccpcli lt-dccpcli \
dccpclo lt-dccpclo \
dccplsi lt-dccplsi \
dccplso lt-dccplso \
dgr2file lt-dgr2file \
dgrcli lt-dgrcli \
dgrclo lt-dgrclo \
dtka lt-dtka \
dtkaadmin lt-dtkaadmin \
dtn2admin lt-dtn2admin \
dtn2adminep lt-dtn2adminep \
dtn2fw lt-dtn2fw \
dtpcadmin lt-dtpcadmin \
dtpcclock lt-dtpcclock \
dtpcd lt-dtpcd \
dtpcreceive lt-dtpcreceive \
dtpcsend lt-dtpcsend \
file2dgr lt-file2dgr \
file2sdr lt-file2sdr \
file2sm lt-file2sm \
file2tcp lt-file2tcp \
file2udp lt-file2udp \
hmackeys lt-hmackeys \
imcadmin lt-imcadmin \
imcadminep lt-imcadminep \
imcfw lt-imcfw \
ionadmin lt-ionadmin \
ionexit lt-ionexit \
ionrestart lt-ionrestart \
ionsecadmin lt-ionsecadmin \
ionunlock lt-ionunlock \
ionwarn lt-ionwarn \
ipnadmin lt-ipnadmin \
ipnadminep lt-ipnadminep \
ipnd lt-ipnd \
ipnfw lt-ipnfw \
lgagent lt-lgagent \
lgsend lt-lgsend \
ltpadmin lt-ltpadmin \
ltpcli lt-ltpcli \
ltpclo lt-ltpclo \
ltpclock lt-ltpclock \
ltpcounter lt-ltpcounter \
ltpdeliv lt-ltpdeliv \
ltpdriver lt-ltpdriver \
ltpmeter lt-ltpmeter \
ltpsecadmin lt-ltpsecadmin \
nm_agent lt-nm_agent \
nm_mgr lt-nm_mgr \
owltsim lt-owltsim \
owlttb lt-owlttb \
psmshell lt-psmshell \
psmwatch lt-psmwatch \
ramsgate lt-ramsgate \
recvfile lt-recvfile \
rfxclock lt-rfxclock \
sdatest lt-sdatest \
sdr2file lt-sdr2file \
sdrmend lt-sdrmend \
sdrwatch lt-sdrwatch \
sendfile lt-sendfile \
sm2file lt-sm2file \
smlistsh lt-smlistsh \
smrbtsh lt-smrbtsh \
stcpcli lt-stcpcli \
stcpclo lt-stcpclo \
tcaadmin lt-tcaadmin\
tcaboot lt-tcaboot\
tcacompile lt-tcacompile\
tcapublish lt-tcapublish\
tcarecv lt-tcarecv\
tcc lt-tcc\
tccadmin lt-tccadmin \
tcp2file lt-tcp2file \
tcpbsi lt-tcpbsi \
tcpbso lt-tcpbso \
tcpcli lt-tcpcli \
tcpclo lt-tcpclo \
udp2file lt-udp2file \
udpbsi lt-udpbsi \
udpbso lt-udpbso \
udpcli lt-udpcli \
udpclo lt-udpclo \
udplsi lt-udplsi \
udplso lt-udplso \
"
if [ "$ION_OPEN_SOURCE" == "1" ];then
KILLPROCESSLIST="${KILLPROCESSLIST} \
amsbenchr lt-amsbenchr \
amsbenchs lt-amsbenchs \
amsd lt-amsd \
amshello lt-amshello \
amslog lt-amslog \
amslogprt lt-amslogprt \
amsshell lt-amsshell \
amsstop lt-amsstop \
bputa lt-bputa \
cfdpadmin lt-cfdpadmin \
cfdpclock lt-cfdpclock \
cfdptest lt-cfdptest \
bpcp lt-bpcp\
bpcpd lt-bpcpd\
"
fi
sw_vers 2> /dev/null > /dev/null
#if sw_vers ran, then we're on a mac system
if [[ ! $? ]]; then
OS_VERS=`sw_vers | grep 10.4`
fi
OSNAME=`uname`
if [ "$OSNAME" == "SunOS" ]; then
KILLCMD="pkill"
PS="/usr/bin/ps"
PS_ARGS="-fe"
PROCESS_LIMIT=1
else
KILLCMD="killall"
PS="ps"
PS_ARGS="-e"
if [[ "$(uname -m)" == "x86_64" ]]; then
PROCESS_LIMIT=64
else
PROCESS_LIMIT=32
fi
fi
#echo "Sending TERM to ${KILLPROCESSLIST}..." # (too noisy)
echo "Sending TERM to the processes..."
echo "${KILLPROCESSLIST}" | xargs -n $PROCESS_LIMIT $KILLCMD 2> /dev/null
sleep 2
echo "Sending KILL to the processes..."
echo "${KILLPROCESSLIST}" | xargs -n $PROCESS_LIMIT $KILLCMD -KILL 2> /dev/null
sleep 2
echo "Checking if all ION processes ended..."
PSFILE="/tmp/ps.$$"
# grab all running processes
${PS} ${PS_ARGS} > ${PSFILE}
# see if any of those still-running processes belong to ION
for PROC in ${KILLPROCESSLIST}; do
grep "[^-a-zA-Z]${PROC}$" ${PSFILE} |\
awk '{printf(" *** Unknown error: process %s not killed...try rebooting\n", $NF);}'
done
rm -f ${PSFILE}
echo "Deleting shared memory to remove SDR..."
if [[ -z "$OS_VERS" ]]; then
# For mac >=10.5 and Linux
for Q in `ipcs -q | grep $USERNAME_CUT | awk '{ print $2 }'`; do ipcrm -q $Q; done
for M in `ipcs -m | grep $USERNAME_CUT | awk '{ print $2 }'`; do ipcrm -m $M; done
for S in `ipcs -s | grep $USERNAME_CUT | awk '{ print $2 }'`; do ipcrm -s $S; done
else
# For mac 10.4, since ipcs on it is weird.
echo "Since ipcs on Apple OSX 10.4 is weird, this script (killm) needs to use sudo, and will ask for your password"
for Q in `sudo ipcs -q | grep $USERNAME_CUT | awk '{ print $3 }'`; do ipcrm -Q $Q; done
for M in `sudo ipcs -m | grep $USERNAME_CUT | awk '{ print $3 }'`; do ipcrm -M $M; done
for S in `sudo ipcs -s | grep $USERNAME_CUT | awk '{ print $3 }'`; do ipcrm -S $S; done
fi
# remove posix named semaphores if this platform maps them into the file system
# Solaris puts them in /tmp/.SEM*, Linux in /dev/shm/sem.*, MacOS doesn't put them in file system
echo "Deleting Posix Named Semaphores..."
rm -f /dev/shm/sem.ion:GLOBAL* /tmp/.SEM*ion:GLOBAL* || (echo '*** Re-run killm with sudo to remove remaining semaphores: '; find /dev/shm /tmp/ -name 'sem.ion:GLOBAL*' -o -name '/tmp/.SEM*ion:GLOBAL*' 2>/dev/null)
echo "Killm completed."
exit 0