You are not logged in.
Hi everyone, I just started to write a program to check CPU usage via /proc/stat but it seems to return completely bogus data. Here's my (crap) code:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
unsigned long user, nice, system, idle;
ifstream procstat ("/proc/stat");
if (!procstat.is_open()){
return 1;
}
for(int i(0); i!=2; ++i)
procstat >> user >> nice >> system >> idle;
procstat.close();
cout << user << "\n" << nice << "\n" << system << "\n" << idle << "\n";
return 0;
}
It returns some values, but they're COMPLETELY different from when I do cat /proc/stat. Any ideas of why?
Thanks!
Edit: Doh, stupid error (as I thought, that loop didn't work), but does anyone know of a clean way of removing the first column in /proc/stat (which happen to be 'cpu')?
Edit2: Fixed, ugh I'm slow today heh.
Last edited by Honken (2008-12-04 04:50:15)
Offline