CMPS-3600 - Fall 2025 - Semester Project

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... 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(); }
Phase-3 - goals --------------- 1. Add a bar graph that gets longer with more cpu use. See image above. 2. Do your file I/O inside a thread. Read the /proc/stat file inside of a thread that's always running. 3. Display usage of more cpu cores and threads. Add a few, or all of them. Give your window a look that will make it easy to see when the processor is working hard and when it's at idle.