Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Daemon java process - is there such a thing?

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?

like image 357
KidCrippler Avatar asked Mar 10 '16 15:03

KidCrippler


1 Answers

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.

like image 192
Nathan Hughes Avatar answered Sep 23 '22 07:09

Nathan Hughes