Mus*_*afa 0 java linux operating-system process
我正在尝试使用Java为Linux编写任务管理器.
我需要获得正在运行的程序列表.以及其他信息:内存使用情况,CPU使用情况......
这可能来自Java吗?
谢谢.
try {
// Execute command
String command = "ps aux";
Process child = Runtime.getRuntime().exec(command);
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
process((char)c);
}
in.close();
} catch (IOException e) {
}
Run Code Online (Sandbox Code Playgroud)
来源(修改):http://www.exampledepot.com/egs/java.lang/ReadFromCommand.html