如何获取Java子进程的pid? [英] How to get the pid of a Java subprocess?
本文介绍了如何获取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.
这篇关于如何获取Java子进程的pid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文