Graceful kill of Apache Commons Exec process

jtb picture jtb · Mar 2, 2011 · Viewed 7.8k times · Source

I am starting an external process in my Java program (on Linux) and I need the ability to send it a SIGTERM signal rather than the SIGKILL that exec.getWatchdog().destroyProcess() is sending. Is there a way that I can more gracefully stop a unix process started with commons-exec? Or can I get the PID so that I can just run the appropriate kill command myself?

Answer

audras picture audras · Sep 18, 2012

ExecuteWatchdog class has method for killing process.

So, you could just create a watchdog with long timeout and use it to kill process when neccessary, i.e.

executor.getWatchdog().destroyProcess();