Skip to content

Instantly share code, notes, and snippets.

@kunals201
Last active May 16, 2019 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunals201/56088edc307608ce9cf8da1360223412 to your computer and use it in GitHub Desktop.
Save kunals201/56088edc307608ce9cf8da1360223412 to your computer and use it in GitHub Desktop.
Get all the current process and print out id of each
package com.knoldus;
import java.util.stream.Stream;
public class CurrentAllProcess {
public static void main(String[] args) throws Exception {
final Stream<ProcessHandle> currentProcesses = ProcessHandle.allProcesses();
currentProcesses.filter(ProcessHandle::isAlive).forEach(processHandle ->
System.out.println(processHandle.pid()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment