I want to get a list with all running processes using Java code?. Can you tell me from which file I can get this information? I would like to get his data from /proc filesystem.
Asked
Active
Viewed 2,593 times
2
-
do you mean windows/linux process? – Satheesh Cheveri Dec 09 '13 at 14:09
3 Answers
8
Just parse the input obtained by running Process p = Runtime.getRuntime().exec("ps -e");
I assume you use linux since you have tagged the question with linux
.
By the way this one is related: How to get a list of current open windows/process with Java?

Community
- 1
- 1

Adam Arold
- 29,285
- 22
- 112
- 207
3
For Linux,
Process process = Runtime.getRuntime().exec("ps -e");
BufferedReader processReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
// Read from BufferedReader
From windows
Process process = Runtime.getRuntime().exec (System.getenv("windir") +"\\system32\\"+"tasklist.exe");
BufferedReader processReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
// Read from BufferedReader

Satheesh Cheveri
- 3,621
- 3
- 27
- 46
2
The numerically named folders in /proc
contain information on the processes on your system.
Getting the contents of those into a human readable format would require some effort in directory traversal, reading documentation and code related to the /proc
FS, and is too wide an area to go into detail with here, but concrete issues related to this would be great SO followup questions :-)
Cheers,

Anders R. Bystrup
- 15,729
- 10
- 59
- 55
-
Yes. How I can get this data and format it into human readable format? – Peter Penzov Dec 09 '13 at 14:14