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,154 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
- 27,872
- 21
- 103
- 189
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,451
- 3
- 25
- 44
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,324
- 10
- 61
- 54
-
Yes. How I can get this data and format it into human readable format? – Peter Penzov Dec 09 '13 at 14:14