[Java] [Linux] Investigating how the implementation of Java child processes on Linux is realized

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.

reference

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

[Java] [Linux] Investigating how the implementation of Java child processes on Linux is realized
Announcing the availability of Java 11 LTS on Amazon Linux 2
On Linux, the time stamp of a file is a little past.
Find out where the java entity is on Linux (CentOS this time)
The origin of Manjaro Linux is "Mount Kilimanjaro"
Calculate the memory sharing rate of Linux processes
How to access the contents of a Linux disk on a Mac (but read-only)
In Python, change the behavior of the method depending on how it is called
[2020July] Check the UDID of the iPad on Linux
How to build Java environment on Ubuntu (Linux)
How strong is your Qiita? Statistics on the number of Contributes seen in the data
Check if the LAN cable is disconnected on Linux
Daemonizing processes on Linux
Put the latest version of Python on linux (Debian) on Chromebook
The story of how the Python bottle worked on Sakura Internet
Switch versions when multiple versions of java are included on Linux
Install the latest version of Git on your Linux server
Get the host name of the host PC with Docker on Linux
Implementation of MathJax on Sphinx
Install the JDK on Linux
Paste the link on linux
How is the progress? Let's get on with the boom ?? in Python
Suspend Thread on Linux (corrected version at the bottom of the article)
How to implement Java code in the background of RedHat (LinuxONE)
How easy is it to synthesize a drug on the market?
Django: Fluctuate the number of child forms depending on the number of input items
[Linux] How to disable the automatic update of the /etc/resolv.conf file (AmazonLinux2)
How to output the output result of the Linux man command to a file
What to do if the inode is exhausted on EC2 Linux
How to use Jupyter on the front end of supercomputer ITO
How does the COTOHA API judge the feeling of "the moon is beautiful"?
How to update the python version of Cloud Shell on GCP
I did a lot of research on how Python is executed