Phase-3 - Show CPU use in real time
-----------------------------------
You may start with procstat.c, xwin89.c, or one of your phases.
Name your program: 
3600/9/bbphase3.c
Compile like this...
   
gcc bbphase3.c -Wall -lX11 -pthreads
We started this program in class Wednesday Oct 22.
 
 
 Code to add since class time...
Code to add since class time...
This code will get your use updating.
Put these variables at top of main()...
    long total = 0;
    long idle = 0;
    long prev_total = 0;
    long prev_idle = 0;
Put this code inside the main loop.
This is the code we wrote in class, with some updates.
        usleep(4000);
        //get the /proc/stat file
        usleep(500000);
        FILE *fpi = fopen("/proc/stat", "r");
        if (fpi) {
            char str[100];
            fscanf(fpi, "%s", str);
            int i;
            prev_total = total;
            prev_idle = idle;
            total = 0;
            for (i=0; i<10; i++) {
                fscanf(fpi, "%s", str);
                total += atol(str);
                if (i == 3)
                    idle = atol(str);
            }
            fclose(fpi);
            float tdiff = total - prev_total;
            float idiff = idle - prev_idle;
            use = (float)idiff / (float)tdiff;
            use = (1.0f - use) * 100.0f;
            render();
        }