zeroturnaround/zt-process-killer

killing a Windows process gracefully throws UnsupportedOperationException

Closed this issue · 1 comments

From the doc I can see "terminate a process gracefully (by default disabled on Windows as it's unsupported - WindowsProcess)". How do I get a running java process as a WindowsProcess and how can I set the gracefulDestroyEnabled = true so that the windows process is terminated gracefully?

WindowsProcess wp = (WindowsProcess) Processes.newPidProcess(process);
wp.setGracefulDestroyEnabled(true);
ProcessUtil.destroyGracefullyAndWait(wp, 10, TimeUnit.SECONDS);

I think it only works with GUI applications.
Note that cast operation only works on Windows. Otherwise you get an instance of UnixProcess.
The example tries to do the graceful stop only. It's not guaranteed that it's successful. You should mostly call ProcessUtil.destroyGracefullyOrForcefullyAndWait instead.