


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The questions and potential solutions for the midterm 1 exam of cs162, a course on operating systems at the university of california, berkeley. The exam includes multiple-choice and problem-solving questions related to cpu scheduling, interrupt handling, caching, and concurrency. Students are expected to indicate the truth or falsehood of given statements, define key terms, analyze the worst possible cpu scheduling algorithms, and evaluate proposed solutions to a river crossing synchronization problem.
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!



      This is a closed bok examination. You have 60 minutes to answer as many questions as possible. The number in parentheses at the beginning of each question indicates the number of points given to the question; there are 60 points in all. Write all of your answers directly on this paper. Make your answers as concise as possible (you needn't cover every available nano-acre with writing).       If there is something in a question you believe is open to interpretation, then please go ahead and interpret BUT state your assumptions in your answer.
For each of the following statements, indicate in one sentence whether the statement is true or false, and why.
(a)   If a set of cooperating threads can correctly time-share one processor, then they will correctly execute on separate processors of a multiprocessor.
(b)   The CPU scheduling policy that minimizes average response time can never lead to starvation.
(c)   If a system employing only segmentation wants to enlarge an addresss space, it is always possible if the total amount of free memory is bigger than the requested enlargement.
For each of the following items, write a one sentence definition.
(a)   Interrupt
(b)   Fully associative cache
(c)   Working set
(d)   Throughput
CS162, Fall/1993 Midterm 1professor (e.g., Professor J. Wawrzynek) 1
(a)   What is the worst possible CPU scheduling algorithm - the one that yields the worst average response time? Assume that the algorithm must run a thread if there is one available, and that a context switch has zero overhead.
(b)   Can round robin ever be the worst possible CPU scheduling algorithm? If so, under what circumstances? If not, explain why not.
(c)   Can FIFO ever be the worst possible CPU scheduling algorithm? If so, under what circumstances? If not, explain why not.
      Consider the clock algorithm for page replacement, being used in its simplest form ("first-chance" replacement, where the clock is only advanced on a page fault, not in the background). Suppose that there are P pages of physical memory in the system and that over a particular interval of time F page faults have occurred.       Express the minimum and maximum number of times that the clock hand could possibly have been advancing during the time interval, as a function of P and F. (Don't worry about "off by one" errors, I'm just looking for the basic idea.)
      you have been hired by your professor to be a grader for CS162. Below you will find some sample solutions to a concurrency assignment. For each poroposed solution, mark it either (i) "correct", if it has no flaws (ii) "incorrect", if it does not work, or (iii) "dangerous", if it sometimes works but sometimes doesn't. You may assume either Mesa-style or Hoare-style condition variables, but if it matters, you must say which one you are using.       If the solution is incorrect or dangerous, explain everything wrong with the solution, and add a minimal amount of code to correct the problem. (NOTE: don't just implement a completely different solution - use the code we provide as a base.)       Here is the sychronization problem: A particular river crossing is shared by both cannibals and missionaries. A boat is used to cross the river, but it only seats three people, and must always carry a full load. In order to guarantee the safety of the missionaries, you cannot put one missionary and two cannibals in the same boat (because the cannibals would gang up and eat the missionary), but all other combinations are legal. Two procedures are needed: MissionaryArrives and CannibalArrives , called by a missionary or cannibal when it arrives at the river bank. The procedures arrange the arriving missionaries and
Problem #2: (8 points) 2
Semaphore *boatCount = new Semaphore(3); int numMissionaries = 0, numCannibals = 0; Lock *boatLock; Condition *boatWait; bool success;
void RowBoat() { success = TRUE; } void MissionaryArrives() { PersonArrives(&numMissionariess); } void CannibalArrives() { PersonArrives(&numCannibals); }
void PersonArrives(int *numPeople) {   for(;;){     boatCount->P();     *numPeople++;     if ((numMissionaries + numCannibals < 3) {       boatLock->Acquire();       boatWait->Wait(boatLock);     } else {       if (!(numMissionaries == 1) && (numCannibals == 2))         RowBoat();       else         success = FALSE;       boatWait->Signal();       boatWait->Signal();     }     numPeople->P();     boatCount->V();     if (success)       return;   } }
Give an engineering estimate (to within a factor of 2 or so) of the number of barbers and hairdressers in the United States. Explain your method.
Problem #6: Extra Credit (2 points) 4