My java program creates a process in the following manner:
ProcessBuilder builder = new ProcessBuilder("phantomjs.exe crawl.js");
Process proc = builder.start();
In case the java program terminates abruptly (could always happen), the phantomjs process (which is not a java process) could stay alive and there would be no way to terminate it.
I want the phantomjs process to be terminated when the enclosing java process terminates (whether abruptly or not).
Is there a way to define the Process
instance as a "daemon" object that terminates automatically when its super process (which is the java process executing the code above) terminates?
The API documentation seems pretty definite, no qualifications or weasel-wording:
The subprocess is not killed when there are no more references to the Process object, but rather the subprocess continues executing asynchronously.
So the parent has to kill it, it won't go away when the parent terminates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With