如何获取Java子进程的pid?

问题描述:

如果我们使用 Runtime.exec 创建一个新的子进程:

If we use Runtime.exec to create a new subprocess:

Process exec(String command) Executes the specified string command in a separate process.

如何获取已创建进程的值?

How to get the value of the created process?

直到 Java 8(包含),你必须使用 解决方法.

Until Java 8 (included), you have to use workarounds.

从 Java 9 开始,有一个新的 Process 类中的getPid 方法.

From Java 9 onwards, there is a new getPid method in the Process class.