Skip to content
Advertisement

What happens in the memory and does a new process always open a new JVM in Java?

  1. What happens in Java when we start a new process using ProccessBuilder.start() or RunTime.getRunTime.exec()?

Will it open a new JVM with a new stack & heap of the new process? Does a new JVM is opened when we create and run a new process?

Advertisement

Answer

What happens in Java when we start a new process using ProccessBuilder.start() or RunTime.getRunTime.exec()?

From here “Starting an operating system process is highly system-dependent.”

Will it open a new JVM with a new stack & heap of the new process? Does a new JVM is opened when we create and run a new process?

No, simply a new system process will be created (similar to start a new process using the system shell like $ program or C:> program.exe).

E.g. running:

JavaScript

produce a new system process (independent of the JVM runtime)

JavaScript

even if you do not wait, the JVM ends their execution but the process is still running

JavaScript

with output

JavaScript

but system process

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement