Java System Properties
Quick Reference Guide


jdk.lang.Process.launchMechanism Java System Property

The jdk.lang.Process.launchMechanism java system property controls how ProcessBuilder spawns new processes on linux.

Default Value

POSIX_SPAWN

On Linux, the default was VFORK before Java 13. Support for POSIX_SPAWN on Linux was added in Java 12, then made the default in Java 13. On other Unix platforms (macOS, BSD, Solaris, AIX), POSIX_SPAWN was already the default before Java 12.

Overview of jdk.lang.Process.launchMechanism

The jdk.lang.Process.launchMechanism system property applies to the java.lang.ProcessBuilder and Runtime.getRuntime().exec() implementation on Unix-like platforms (Linux, macOS, BSD, Solaris, AIX). The set of accepted values varies by platform: VFORK is only supported on Linux.

Possible Values

Related System Properties

Here are some other Java system properties:

References

Supported Since

Java has supported the jdk.lang.Process.launchMechanism system property since 12.

Setting jdk.lang.Process.launchMechanism on Startup

You can set the jdk.lang.Process.launchMechanism java system property during startup of the java runtime using the -D command line argument:

java -Djdk.lang.Process.launchMechanism=POSIX_SPAWN MyAppMain

You may also be able to specify jdk.lang.Process.launchMechanism via the JAVA_TOOL_OPTIONS environment variable:

JAVA_TOOL_OPTIONS=-Djdk.lang.Process.launchMechanism=POSIX_SPAWN

Setting / Reading jdk.lang.Process.launchMechanism at Runtime

You can set jdk.lang.Process.launchMechanism at runtime with the following Java code:

System.setProperty("jdk.lang.Process.launchMechanism", "POSIX_SPAWN");

WARNING: Depending on the property and JVM version using setProperty may or may not work if the JDK Java class that uses this variable has already been loaded. The value of the jdk.lang.Process.launchMechanism system property may be cached within an internal private static variable of the implementing class.

To read the value of jdk.lang.Process.launchMechanism at runtime, you can use this Java code:

String propertyValue = System.getProperty("jdk.lang.Process.launchMechanism");
if (propertyValue != null) {
    System.out.println("jdk.lang.Process.launchMechanism = " + propertyValue);
} else {
    System.out.println("jdk.lang.Process.launchMechanism was null");
}