EN
Java 9+ - get current process ID (PID)
9 points
In this short article, we would like to show how to get the current process ID (PID) in Java 9+.
Quick solution:
xxxxxxxxxx
1
long pid = ProcessHandle.current().pid();
xxxxxxxxxx
1
package com.example.demo;
2
3
public class Program {
4
5
public static void main(String[] args) {
6
7
long pid = ProcessHandle.current().pid();
8
9
System.out.println("PID: " + pid);
10
}
11
}
Example output:
xxxxxxxxxx
1
PID: 7788