I need to write code that
- start the unix process with
Runtime.getRuntime().exec("java -jar MyServerRunner -port MYPORT"); - find the PID of the process by running the command from the java code
lsof -t -i: MYPORT - and kill it pid
kill -9 PID (also by running a command from java code) - and then execute other commands
BUT
if I execute this command using Runtime.getRuntime().exec() , my program exits with exit code 137 - this means that when I run Runtime.getRuntime().exec("kill -9 PID") I kill the process My java programs, but not the program that I run from the code.
How can I kill ONLY the process that I ran from the code?
PS maybe i should use ProcessBuilder?
source share