I need the ability to kill linux process using java. I have used the commands below but it appears i don't have the permissions to kill the process even though the process is of the same user. I have also tried running the application with sudo ie. "sudo java -jar appname.jar"
private static void forceKillRunningProcess() throws Exception{
//Runtime.getRuntime().exec("sudo pkill -f 'application.jar'");
ProcessBuilder pb = new ProcessBuilder("sudo","pkill","-f", "\"application.jar\"");
pb.start();
}
the commands above work if in CLI but not in java. Is there a work around?