Daemon java process - is there such a thing?

Viewed 404

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?

2 Answers

Not a great solution, but you could always check periodically the PID of the parent from the children.

Related