I usually use only C / C ++, but I had a chance to worry about the implementation of Java application below when debugging, so make a note. (I haven't touched Java so I'm sorry if I made a mistake)
It seems that ProcessBuilder
is used when executing an external program in Java.
At that time, a child process is created, and I checked at the source level whether the child process
is similar to the child process
in Linux.
Someone was investigating something similar, so I quoted halfway.
java.lang.ProcessBuilder.start(…) //OS common
→ java.lang.ProcessImpl.start(…) //Class for UNIX-like OS(Under the solaris folder)
→ java.lang.UnixProcess.<init> // UNIXProcess.java.linux
--------------------Native code from here(C language) ---------------------
→ Java_java_lang_UNIXProcess_forkAndExec(...)
(Vfork at the end of this function()Is done)
Quote: Peek inside Process Builder-Apprentice Programming Diary
As above, the C code for each platform is finally called. For the platform abstraction layer of JDK including JNI of Coco et al., See the following articles. C API that abstracts the platform (Java version) --Qiita
With OpenJDK8, the specific sources are as follows. (Linux but the path is included under solaris)
jdk8/jdk8/jdk: d94613ac03d8 src/solaris/native/java/lang/UNIXProcess_md.c
I knew it at the time of the name Java_java_lang_UNIXProcess_forkAndExec
, but fork => exec.
More specifically, it looks like vfork
=> ʻexecve` on Linux.
So, in conclusion, I was able to confirm that creating a child process with Java's ProcessBuilder
is an implementation of a general process in Linux.
Peek inside ProcessBuilder-Apprentice programming diary jdk8/jdk8/jdk: d94613ac03d8 src/solaris/native/java/lang/UNIXProcess_md.c C API that abstracts the platform (Java version) --Qiita
Recommended Posts