I want to find idle percentage of processor but it is showing all procinfo output
Process p = Runtime.getRuntime().exec("procinfo | grep idle");
while((s=stdInput.readLine())!=null) {
System.out.println(s);
}
I want to find idle percentage of processor but it is showing all procinfo output
Process p = Runtime.getRuntime().exec("procinfo | grep idle");
while((s=stdInput.readLine())!=null) {
System.out.println(s);
}
import java.io.InputStream;
public class ProcInfo
{
public static void main(String args[])
{
String[] command = { "/bin/sh", "-c", "procinfo | grep -oP '^idle.* \\K[0-9.]+%'" };
try
{
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
InputStream i = p.getInputStream();
byte[] b = new byte[16];
i.read(b, 0, b.length);
System.out.println(new String(b));
}
catch (Exception e)
{
System.out.println(e);
}
}
}
Special Thanks to Cyrus for the command.