#include #include #include #include /* test6.c * * There are two processes: Main and Proc A with rates 20 and 30 respectively. * After 5 seconds from the system start, Proc A sleeps for 30 seconds. * During that time, Main monopolizes the CPU. When Proc A wakes up from sleep, * its Pi value should get updated and we can expect it to monopolize the CPU * for some time, till its Pi value becomes on par with that of Main. Calculate * how much time Proc A takes after waking up to catch up with Main. Report this * value along with the results of test5.c. Compare your results with those * calculated theoretically. */ int prch(char c); int prA, prB, prC; unsigned long ctr1000; int main() { int i, j = 0; kprintf("\n\nTEST6:\n"); resume(prA = create((int *) prch, 2000, 30, "proc A", 1, 'A')); while (1) { /* printing to check status */ kprintf(":%c %d %d:", 'D', j, ctr1000); for (i = 0; i < 10000; i++) ; j++; } } int prch(char c) { int i, j = 0; while (1) { /* printing to check status */ kprintf(":%c %d %d:", c, j, ctr1000); if (ctr1000 >= 5000 && ctr1000 <= 6000) sleep(30); /* sleep after 5 secs for 30 secs */ for (i = 0; i < 10000; i++) ; j++; } }