我正在将脚本从 php 转换为 java,但我找不到转换这部分的方法
exec('free -mo', $out); <-- Converted
preg_match_all('/\s+([0-9]+)/', $out[1], $matches);
list($total, $used, $free, $shared, $buffers, $cached) = $matches[1];
执行结果是这样的:
我正在将脚本从 php 转换为 java,但我找不到转换这部分的方法
exec('free -mo', $out); <-- Converted
preg_match_all('/\s+([0-9]+)/', $out[1], $matches);
list($total, $used, $free, $shared, $buffers, $cached) = $matches[1];
执行结果是这样的:
自己解决
String info = cmdExec("cat /proc/meminfo");
info = info.replaceAll(" ", "");
info = info.replaceAll("kB", "");
String[] lines = info.split(System.getProperty("line.separator"));
df = new DecimalFormat("0");
Integer MemTot = Integer.parseInt(df.format(Integer.parseInt(lines[0].substring(lines[0].indexOf(":") + 1)) / 1024.0f));
Integer MemFree = Integer.parseInt(df.format(Integer.parseInt(lines[1].substring(lines[1].indexOf(":") + 1)) / 1024.0f));
Integer Buffers = Integer.parseInt(df.format(Integer.parseInt(lines[2].substring(lines[2].indexOf(":") + 1)) / 1024.0f));
Integer Cached = Integer.parseInt(df.format(Integer.parseInt(lines[3].substring(lines[3].indexOf(":") + 1)) / 1024.0f));
Integer Used = MemTot - MemFree;
Integer fMemFree = MemFree + Buffers + Cached;
Integer MemUsed = Used - Buffers - Cached;