I know the answer depends on the particular JVM, but I would like to understand how it is usually implemented? Is it in terms of popen (posix)? In terms of efficiency do I need to keep something in mind (other than using a Buffered stream as suggested by the javadoc). I would be interested to know if there is a general reference about implementations of JVMs which answers such questions.
+3
A:
Look at the source of JDK.
In this case, for Unix, look at UnixProcess class.it does a fork and exec and wraps file and buffer streams around native file descriptors.
pid = forkAndExec(prog,
argBlock, argc,
envBlock, envc,
dir,
redirectErrorStream,
stdin_fd, stdout_fd, stderr_fd);
stdin_stream = new BufferedOutputStream(new FileOutputStream(stdin_fd));
For native code look at: native/java/lang/UNIXProcess_md.c
It does something interesting! it opens pipes and give them as STDIN, STDOUT, STDERR to child and other side of pipes are used by parent!
In short IPC mechanism is pipes.
Fakrudeen
2010-02-26 06:52:11