1

I was wondering if anybody knew with any certainty whether ProcessBuilder/Runtime.exec() executes inside the space of the JVM's memory or whether it uses completely separate system memory and somehow sends the output to Java. I could not find any documentation on the subject.

I assume it is the former due to security issues and being able to read output, but I would like to make absolutely sure.

3 Answers 3

7

The new process runs outside the Java process that started it. Allocation of memory to the new process is managed by the operating system, as part of process management.

The Java class ProcessBuilder, which provides an interface for starting and communicating with the new process, runs inside the Java process.

Sign up to request clarification or add additional context in comments.

1 Comment

Got it. Thank you for the concise answer!
0

Seems pretty clear that exec launches a new process, or program for those not versed in operating system terminology. That's why it has input output facilities, ability to set the environment, and ability to wait on the external program returning.

The first line of the javadoc says it all.

Executes the specified string command in a separate process.

The command argument is parsed into tokens and then executed as a command in a
separate process. The token parsing is done by a StringTokenizer created by the 
call:

     new StringTokenizer(command)


with no further modifications of the character categories. This method has exactly
the same effect as exec(command, null).

Comments

0

From the concurrency reference of Java SE, it is said that:

A process has a self-contained execution environment. A process generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space.

If you are interested in the internals, check the UNIXProcess class from the openJDK.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.