Просмотр поста

.
Swank
Сексуальность валенка

Вот так вот все заработало

int cpuUsage() {
    double load = 0;
    unsigned long total, c, n, s, i = 0;
    unsigned long c1, n1, s1, i1 = 0; 

    FILE *f = fopen("/proc/stat", "r");
    if (fscanf(f, "cpu %lu %lu %lu %lu", &c, &n, &s, &i) < 4) {
        fclose(f);
        return -1;
    }
    fclose(f);
    sleep(1);
    f = fopen("/proc/stat", "r");
    if (fscanf(f, "cpu %lu %lu %lu %lu", &c1, &n1, &s1, &i1) < 4) {
        fclose(f);
        return -1;
    }
    fclose(f);

    c = c1-c;
    n = n1 -n;
    s = s1 -s;
    i = i1 - i;

    total = c + n + s + i;
    load =  100.0 * ((c + n + s)/(double)total);
    return load;
}