1

We have requirement of creating a new process from Java. I know we can create new sub-processes by using ProcessBuilder and Runtime.exec but our requirement is to create a complete new process. In other words, we do not want to have the spawned process exit when the JVM does.

Does anyone have ideas how we can do this using Java API or a 3rd party framework?

Greg Kopff
  • 15,945
  • 12
  • 55
  • 78
Amit Verma
  • 167
  • 1
  • 3
  • 8
  • 4
    What do you mean by 'complete new process'? The two API you mentioned create actual processes. – xiaofeng.li Jun 05 '12 at 03:45
  • 1
    Runtime.exec and ProcessBuilder both do create complete new processes. – FThompson Jun 05 '12 at 03:46
  • 1
    These classes creates the subprocess of the process from where the ProcessBuilder.start() method is called .In this case owner of this subprocess is the parent process from which it is started. – Amit Verma Jun 05 '12 at 04:08
  • Presumably you won't want to process to exit when the JVM does? Or do you have other reasons for wanting it to be "detached"? – Greg Kopff Jun 05 '12 at 04:09
  • 1
    @GregKopff:You are right , i dont want my process to exit when JVM does. – Amit Verma Jun 05 '12 at 04:13
  • @AmitVerma Are you trying to create a new JVM process or is it a separate binary, that you want to execute from the Java code. I am curious to know that – Anupam Saini Jun 05 '12 at 04:57

2 Answers2

1

I've made a test java program which spawns another process. When java program exits, the spawned process is still alive. So what is the problem? Anyway, in case of trouble you always can spawn a shell (.bat) file and spawn your process from it.

Alexei Kaigorodov
  • 13,189
  • 1
  • 21
  • 38
0

Do not think that can be done independently without taking help from OS.However, there is a similar thread here which talks about the same.

How do I launch a completely independent process from a Java program

Community
  • 1
  • 1
UVM
  • 9,776
  • 6
  • 41
  • 66