Java 9에서는 PID 를 검색할 수 있습니다. 네이티브 호출을 통해 프로세스를 처리하고 ProcessHandle을 통해 달성할 수 있습니다. . 또한 현재 실행 중인 Java 프로세스(JVM ) 및 정보 (ProcessHandle의 내부 클래스 ) 프로세스에 대한 세부 정보가 포함된 클래스입니다. 스냅샷 을 반환할 수도 있습니다. 시스템에서 현재 실행 중인 모든 프로세스 중
예시
import java.lang.ProcessHandle.Info; public class ProcessAPIChanges { public void detailedAPIInfo(ProcessHandle processHandle) { Info processInfo = processHandle.info(); System.out.println("Detailed Process Info is Provided Below: "); System.out.println("[Executable Name] " + processInfo.command().get()); System.out.println("[User Name] " + processInfo.user().get()); System.out.println("[Start Time] " + processInfo.startInstant().get().toString()); } public static void main(String args[]) { System.out.println("Process API Changes (Core Library) "); ProcessAPIChanges processAPIChanges = new ProcessAPIChanges(); ProcessHandle processHandle = ProcessHandle.current(); System.out.println("[Current Process Id] " + processHandle.pid()); processAPIChanges.detailedAPIInfo(processHandle); ProcessHandle.allProcesses() .filter(ph -> ph.info().command().isPresent()) .limit(4).forEach((process) -> processAPIChanges.detailedAPIInfo(process)); } }
출력
Process API Changes (Core Library) [Current Process Id] 5724 Detailed Process Info is Provided Below: [Executable Name] C:\Program Files\Java\jdk-9.0.4\bin\java.exe [User Name] Tutorialspoint\User [Start Time] 2020-04-01T07:35:43.152Z Detailed Process Info is Provided Below: [Executable Name] C:\WINDOWS\System32\taskhostex.exe [User Name] Tutorialspoint\User [Start Time] 2020-04-01T04:14:36.241Z Detailed Process Info is Provided Below: [Executable Name] C:\Program Files\Synaptics\SynTP\SynTPEnh.exe [User Name] Tutorialspoint\User [Start Time] 2020-04-01T04:14:36.257Z Detailed Process Info is Provided Below: [Executable Name] C:\WINDOWS\explorer.exe [User Name] Tutorialspoint\User [Start Time] 2020-04-01T04:14:36.335Z Detailed Process Info is Provided Below: [Executable Name] C:\Program Files (x86)\Dell Wireless\Bluetooth Suite\BtvStack.exe [User Name] Tutorialspoint\User [Start Time] 2020-04-01T04:14:51.594Z