0

I am making some monitoring thread. Have stored the process IDs (PID) in a hash map. In thread I am retrieving those PID and on certain condition want to kill particular PID. I searched on web, for windows environment the kill command was : Runtime.getRuntime().exec("taskkill /F /PID "+PID_id); where PID_id is the PID I get from map. I want to know, how can I do such thing in ubuntu(Linux) environment.

JPG
  • 1,247
  • 5
  • 31
  • 64

1 Answers1

1
Process process = Runtime.getRuntime().exec("kill -9 "+PID_id);
int retCode = process.waitFor();
Saril Sudhakaran
  • 1,109
  • 9
  • 17
  • if you want return code , the java program has to wait for the proces to complete and do a process.waitFor() – Saril Sudhakaran Dec 02 '15 at 13:31
  • @sarilsudhakaran what will happen if I don't use `int retCode = process.waitFor();`. I want process with PID_id immediately killed. Don't want to wait for its completion. – JPG Dec 03 '15 at 04:39
  • waitFor() is called to make sure that its killed and check the return code . you can ignore that call and continue processing – Saril Sudhakaran Dec 07 '15 at 10:17