如何在 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