
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
What are the core library changes in Process API in Java 9?
In Java 9, one can retrieve the PID of the process through a native call and can be achievable through the ProcessHandle. We can also retrieve information about the currently running Java Process (JVM) and Info (inner class of ProcessHandle) class that contains details about the process. We can also return a snapshot of all currently running processes in the system.
Example
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)); } }
Output
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
- Related Articles
- What are the improvements in Process API in Java 9?
- What are the new methods added to Process API in Java 9?
- How to get the parent process of the Process API in Java 9?
- What are the changes in Memory Management in Java 9?
- What are the core interfaces of Reactive Streams in Java 9?
- How to terminate/destroy a process using Process API in Java 9?
- How to traverse a process tree of Process API in Java 9?
- What are the CompletableFuture API improvements in Java 9?\n
- What are the changes of class loaders in Java 9?
- What are the steps to execute Flow API in Java 9?
- How to get all children of a process using Process API in Java 9?
- What are the new features added to Stream API in Java 9?
- How to retrieve all processes data of Process API in Java 9?
- StackWalker API in Java 9?
- What is Platform Logging API in Java 9?

Advertisements