Wiki source code of Killing WOA Processes
Last modified by David Avendasora on 2010/11/30 06:45
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | This is one of the most vexing question. How to kill a runaway WebObjects application? The ps command does not give you any information as it lists the process simply as java. | ||
2 | |||
3 | Try to use lsof. You need to run it with admin privileges so the command is | ||
4 | |||
5 | {{noformat}} | ||
6 | |||
7 | sudo lsof -i tcp:xxxx | ||
8 | |||
9 | {{/noformat}} | ||
10 | |||
11 | Alternatively you can have a script: | ||
12 | |||
13 | {{code}} | ||
14 | |||
15 | #!/bin/sh | ||
16 | # | ||
17 | # portslay: kill the task listening on the specified TCP port | ||
18 | # | ||
19 | kill -9 `lsof -i tcp:$1 | grep LISTEN | awk '{ print $2;}'` | ||
20 | |||
21 | {{/code}} | ||
22 | |||
23 | You will also have to do a sudo for the script to run. | ||
24 | |||
25 | For those stuck with the CLOSE_WAIT problems try this: | ||
26 | |||
27 | {{noformat}} | ||
28 | |||
29 | sudo lsof -i tcp:xxxx | ||
30 | |||
31 | {{/noformat}} | ||
32 | |||
33 | Alternatively you can have a script: | ||
34 | |||
35 | {{code}} | ||
36 | |||
37 | #!/bin/sh | ||
38 | # | ||
39 | # portslay: kill the task listening on the specified TCP port | ||
40 | # | ||
41 | kill -9 `lsof -i tcp:$1 | grep CLOSE_WAIT | awk '{ print $2;}'` | ||
42 | |||
43 | {{/code}} | ||
44 | |||
45 | run it by doing: | ||
46 | |||
47 | {{noformat}} | ||
48 | |||
49 | sudo ./portslay xxxx-yyyy | ||
50 | |||
51 | {{/noformat}} | ||
52 | |||
53 | where xxxx is the first port and yyyy the last port | ||
54 | |||
55 | ---- | ||
56 | |||
57 | how about (pref. inside a script): | ||
58 | |||
59 | {{noformat}} | ||
60 | |||
61 | ps aux | grep java | grep <appName> | grep -v grep | awk '{ print"kill -9 "$2 }' | sh | ||
62 | |||
63 | {{/noformat}} | ||
64 | |||
65 | \\ | ||
66 | |||
67 | === Mike Schrag === | ||
68 | |||
69 | I just use | ||
70 | |||
71 | {{noformat}} | ||
72 | |||
73 | ps auxww | ||
74 | |||
75 | |||
76 | {{/noformat}} | ||
77 | |||
78 | which will show the full commandline. You can see the app name from this view. | ||
79 | |||
80 | === Fabian Peters === | ||
81 | |||
82 | On FreeBSD one needs to set | ||
83 | |||
84 | {{noformat}} | ||
85 | |||
86 | kern.ps_arg_cache_limit=1024 | ||
87 | |||
88 | {{/noformat}} | ||
89 | |||
90 | in /etc/sysctl to reveal the full command line with ps -auxww. To set it immediately: | ||
91 | |||
92 | {{noformat}} | ||
93 | |||
94 | sysctl kern.ps_arg_cache_limit=1024 | ||
95 | |||
96 | {{/noformat}} | ||
97 | |||
98 | Alternatively, one can use Johan's script below. | ||
99 | |||
100 | === Johan Henselmans === | ||
101 | |||
102 | I have written a small script that uses lsof to find the process by looking at some specific file that is opened, the returned processes can then be used to kill the process | ||
103 | |||
104 | {{code}} | ||
105 | |||
106 | #!/bin/sh | ||
107 | |||
108 | if [ $# = 0 ]; then | ||
109 | echo "" | ||
110 | echo " usage: $0 javaname(s)" | ||
111 | echo " The current processes that containt javaname will be displayed" | ||
112 | echo " eg: $0 JavaMonitor.woa" | ||
113 | echo "" | ||
114 | exit 1 | ||
115 | fi | ||
116 | |||
117 | OS=`uname -s` | ||
118 | # echo $OS | ||
119 | case ${OS} in | ||
120 | 'FreeBSD') | ||
121 | LSOF=/usr/local/sbin/lsof | ||
122 | ;; | ||
123 | 'Linux') | ||
124 | LSOF=/usr/sbin/lsof | ||
125 | ;; | ||
126 | 'Darwin') | ||
127 | LSOF=/usr/sbin/lsof | ||
128 | ;; | ||
129 | *) | ||
130 | echo "no lsof command available on this OS!"; | ||
131 | exit 1 | ||
132 | ;; | ||
133 | esac | ||
134 | |||
135 | for i in $* | ||
136 | do | ||
137 | ${LSOF} -c java | grep -i $i | awk '{print $2}' | sort -u; | ||
138 | done | ||
139 | |||
140 | {{/code}} |