code_junkie

How do I get rid of Java child processes when my Java app exits/crashes?

Nov 12th, 2011
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. final String[] cmd = {"<childProcessName>"};
  2. Process process = Runtime.getRuntime().exec(cmd);
  3.  
  4. final String[] cmd = {"<childProcessName>"};
  5. final Process process = Runtime.getRuntime().exec(cmd);
  6. Runnable runnable = new Runnable() {
  7. public void run() {
  8. process.destroy();
  9. }
  10. };
  11. Runtime.getRuntime().addShutdownHook(new Thread(runnable));
  12.  
  13. killall <childProcessName>
Add Comment
Please, Sign In to add comment