i want to get infomation about other running processes in my os. (two things, process 'name' and 'path'.)
now, i'm using linux command like a "ps command".
Process process = Runtime.getRuntime().exec("ps x")
but because i want to run this in windows too, i'm searching other function can be works in windows and linux.
there are any java class or function have not os dependency?
The updated Process API in Java 9 through JEP 102 will help you if you're willing to upgrade early... This provides platform agnostic access to process trees...
See ProcessHandle.allProcesses()
Example
ProcessHandle.allProcesses().forEach(processHandle ->
System.out.println("PID: " + processHandle.getPid() +
", command: " + processHandle.info().command().orElse("Unknown")));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With