0

I wrote a process manager program one of the things that it does is to exit all running processes when it shut down ,so there is the code

public void stop_all() throws IOException {
   Process p = Runtime.getRuntime().exec("kill -9 -1");
   System.out.println("killed");
}

and there is the action on the button

private void exitButton(java.awt.event.ActionEvent evt) {                                         
Run ob = new Run();
    try {
        ob.stop_all();
    } catch (IOException ex) {
        Logger.getLogger(mainmenu.class.getName()).log(Level.SEVERE, null, ex);
    }

this.dispose();

}

i have no idea why it doesn't work , i execute that command in the terminal and it works fine

please help :)

  • You can try to read the process' output to see if there are any errors, [here is an example](http://stackoverflow.com/questions/8149828/read-the-output-from-java-exec) but my guess is that this Java program doesn't have the necessary permissions to run that command. – Titus May 08 '16 at 21:12
  • What do you mean by "program"? Do you mean a .jar? If so try running the jar in terminal with java -jar and post the error output – 2ARSJcdocuyVu7LfjUnB May 08 '16 at 21:20
  • Are you not getting any exception/error? If yes, please post it here. – PseudoAj May 08 '16 at 21:23
  • i don't get any error or exception by debugging i found that the code pass by the function and run it and it doesn't do what it should do – Ansam M. Abd El-Rasoul May 08 '16 at 21:59

1 Answers1

0

I am still skeptical about the permissions of the program. But, from this reference you need to specify the command path in your exec().

So your code should probably be:

public void stop_all() throws IOException {
   Process p = Runtime.getRuntime().exec("/bin/kill -9 -1");
   System.out.println("killed");
}
Community
  • 1
  • 1
PseudoAj
  • 5,234
  • 2
  • 17
  • 37