@@ -125,16 +125,7 @@ private static int killWinProcess(Process process) {
125
125
int exitValue ;
126
126
127
127
try {
128
- Field f = process .getClass ().getDeclaredField ("handle" );
129
- f .setAccessible (true );
130
- long hndl = f .getLong (process );
131
-
132
- Kernel32 kernel = Kernel32 .INSTANCE ;
133
- WinNT .HANDLE handle = new WinNT .HANDLE ();
134
- handle .setPointer (Pointer .createConstant (hndl ));
135
- int pid = kernel .GetProcessId (handle );
136
-
137
- killPID ("" + pid );
128
+ killPID ("" + getProcessId (process ));
138
129
exitValue = waitForProcessDeath (process , 10000 );
139
130
} catch (Exception ex ) {
140
131
LOG .log (Level .WARNING , "Process refused to die after 10 seconds, and couldn't taskkill it" , ex );
@@ -184,28 +175,24 @@ private static void closeAllStreamsAndDestroyProcess(Process process) {
184
175
}
185
176
186
177
static int getProcessId (Process p ) {
187
- if ( thisIsWindows ()) {
188
- try {
178
+ try {
179
+ if ( Platform . getCurrent (). is ( WINDOWS )) {
189
180
Field f = p .getClass ().getDeclaredField ("handle" );
190
181
f .setAccessible (true );
191
182
long hndl = f .getLong (p );
192
183
193
184
Kernel32 kernel = Kernel32 .INSTANCE ;
194
185
WinNT .HANDLE handle = new WinNT .HANDLE ();
195
186
handle .setPointer (Pointer .createConstant (hndl ));
196
- int pid = kernel .GetProcessId (handle );
197
- return pid ;
198
- } catch (Exception e ) {
199
- throw new RuntimeException ("Couldn't detect pid" , e );
200
- }
201
- } else {
202
- try {
203
- Field f = p .getClass ().getDeclaredField ("pid" );
204
- f .setAccessible (true );
205
- return (Integer ) f .get (p );
206
- } catch (Exception e ) {
207
- throw new RuntimeException ("Couldn't detect pid" , e );
187
+ return kernel .GetProcessId (handle );
208
188
}
189
+
190
+ Field f = p .getClass ().getDeclaredField ("pid" );
191
+ f .setAccessible (true );
192
+ return (Integer ) f .get (p );
193
+
194
+ } catch (Exception e ) {
195
+ throw new RuntimeException ("Couldn't detect pid" , e );
209
196
}
210
197
}
211
198
0 commit comments