简体   繁体   中英

kill ubuntu process using PID in java

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.

Process process = Runtime.getRuntime().exec("kill -9 "+PID_id);
int retCode = process.waitFor();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM