3

I have written a Java program to run some other processes for special tasks. I want to satisfy a grate condition which is all child processes should exit if the main java process ended or exited. I used this code in my java program:

processBuilder = new ProcessBuilder(command);
processBuilder.redirectErrorStream(true);
process = processBuilder.start();

I see sometimes this won't happen. Sample command to execute may be calling a program or shell file. I used waitFor() but it was not effective. I use Ubuntu 12.04 and java 7.21. Can anybody help me about this?

EDIT: I want the child process be stopped by the OS even if main java process exited unexpectedly.

sajad
  • 2,094
  • 11
  • 32
  • 52
  • possible duplicate of [How do I get rid of Java child processes when my Java app exits/crashes?](http://stackoverflow.com/questions/261125/how-do-i-get-rid-of-java-child-processes-when-my-java-app-exits-crashes) – Floris Jan 07 '14 at 12:25
  • The solution specified there is using `shutdownhook`. I want the child process be stopped by the OS even if java process exited unexpectedly. – sajad Jan 07 '14 at 12:56
  • I believe the **question** I linked is the same as yours; but I agree the **answer** is unsatisfactory. Perhaps the use of a wrapper (see e.g. http://wrapper.tanukisoftware.com/doc/english/index.html ) can help? I have withdrawn my "close" flag - let's see if someone comes up with a better answer than "it can't be done". – Floris Jan 07 '14 at 15:18

0 Answers0