import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
* 取得linux系统下的cpu、内存信息
*
* <p>@author javer QQ:84831612</p>
* @date 2005
*/
public final class LinuxSystemTool
{
/**
* get memory by used info
*
* @return int result
* result.length==4;int[0]=MemTotal;int=MemFree;int=SwapTotal;int=SwapFree;
* @throws IOException
* @throws InterruptedException
*/
public static int getMemInfo() throws IOException, InterruptedException
{
File file = new File("/proc/meminfo");
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
int result = new int;
String str = null;
StringTokenizer token = null;
while((str = br.readLine()) != null)
{
token = new StringTokenizer(str);
if(!token.hasMoreTokens())
continue;
str = token.nextToken();
if(!token.hasMoreTokens())
continue;
if(str.equalsIgnoreCase("MemTotal:"))
result[0] = Integer.parseInt(token.nextToken());
else if(str.equalsIgnoreCase("MemFree:"))
result = Integer.parseInt(token.nextToken());
else if(str.equalsIgnoreCase("SwapTotal:"))
result = Integer.parseInt(token.nextToken());
else if(str.equalsIgnoreCase("SwapFree:"))
result = Integer.parseInt(token.nextToken());
}
return result;
}
/**
* get memory by used info
*
* @return float efficiency
* @throws IOException