如何在 Java 9 中获取进程 API 信息快照?
Java 9 通过包含新方法以及引入新接口ProcessHandle 和ProcessHandle.Info来改进Process API,以获取有关进程及其信息的全部详细信息。
ProcessHandle 接口可以识别和提供对本机进程的控制。可以监视每个单独的进程以活动、列出其子级、获取有关进程的信息或销毁 它。ProcessHandle.Info接口提供有关进程的快照 信息。
语法
ProcessHandle.Info info()
示例
public class ProcessSnapShotTest {
public static void main(String[] args) {
ProcessHandle currentProcessHandleImpl = ProcessHandle.current();
// Process snapshot of the current running process with ProcessHandle.Info:
ProcessHandle.Info processInfo = currentProcessHandleImpl.info();
System.out.println("nProcess snapshot of the current running process:");
System.out.println("User : " + processInfo.user().get());
System.out.println("Start Time : " + processInfo.startInstant().get());
}
}输出
Process snapshot of the current running process: User : Tutorialspoint\User Start Time : 2020-05-01T05:44:41.458Z
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP