Computer Science 422/622 Test 1 - 25 Feb 1997 Name________________________ 1. Answer the following T or F. ___ a. A process that did a tremendous amount of computation and very little I/O would typically spend less time in the "Blocked" state than one which did a large amount of I/O and a small amount of computation. ___ b. A process could never enter the "Ready" state more times than it entered the "Blocked" state. ___ c. A process would typically enter the "Out Ready" state more often than it entered the (In)Ready state. 2. Suppose a malicious user of a Unix OS (such as SUN's) running on an Intel CPU writes the C program shown on the left. The function CLI is an assembly language module shown on the right main() CLI: proc { cli /* disable ints */ CLI(); ret while (1); } When the hacker tries to compile and execute it. Which of the following best describes what will occur. a. The hackers attempt to build b. The hacker can build an a.out an a.out will fail because users and when he starts it the system aren't allowed to write in assembly. will crash. c. The hacker's a.out will loop d. The hacker's a.out will be indefinitely but other processes terminated the first time will be dispatched whenever the it attempts to execute the hacker's is preempted. cli instruction. Consider the following "solution" to the mutual exclusion problem int using[2]; void dek_lock(int pid) /* Pid = 0 or 1 */ { int me, other; [1] me = pid; [2] other = me ^ 1; [3] using[me] = 1; [4] while(using[other]); [5] return; } 3. The above solution is: a. Livelock prone b. Unsafe c. Deadlock prone d. All of the above 4. The problem a. will occur EVERY time a b. may occur if a process is preempted process gets prempted between lines [3] and [4] (but can between lines [3] and [4]. occur nowhere else). c. may occur if a process is d. Will occur if a process is preempted anywhere between preempted anywhere between lines [1] [5]. lines [1] [5]. 5. If lines [3] and [4] are interchanged the "solution" becomes: a. Livelock prone b. Unsafe c. Deadlock prone d. Correct 6. Identify the mechanism used to accomplish each of the following functions. ___ 1. Allows OS to regain control a. A software interrupt. from a looping program. b. A hardware interrupt. ___ 2. Is used by an application to request a service from the OS (make a system call) c. A subroutine call. ___ 3. Is used by the OS low level d. An interrupt return (IRET) scheduler to DISPATCH an instruction. application program. 7. Suppose PS == (no overhead RR) scheduling is used and four jobs are started at the same time. Two of the jobs require 2 hours of CPU time and the other two require 3 hours. What is the average response time of the jobs. 8. What will be the average respose time for the four jobs be if they are run with non preemptive FCFS scheduling and the jobs two 3 hour jobs are run first. 9. Suppose 2 processes are to be run and EACH ONE requires 12 minutes of processor time and 4 minutes of disk time. Suppose they are run on an ideal multitasking system in which perfect overlap of CPU and disk activity is achieved with no OS overhead at all. If they start at the same time, how long will it be until they finish? 10. Consider the following code segment: [1] pid = fork() [2] pipe(pd); [3] if (pid == 0) [4] child_proc(); [5] else [6] parent_proc(); a. How many pipes (not pipe handles) will be created? b. Will the parent and child be able to communicate using the pipe(s)? (Yes or No). If your answer is no, describe how to fix the code so that they can. 11. Answer the following T or F: (These questions refer to "steady state" conditions (i.e. ignore transient states that might occur DURING the actual execution of a wait or signal). ___ a. A semaphore that has the value 1 never has even one suspended process. ___ b. A semaphore that has at least one suspended process always has the value 0. ___ c. A signal operation on a semaphore that has a 0 value at the time of the signal always causes the value of the semaphore to be incremented. ___ d. A wait operation on a semaphore with a non-empty wait queue never changes the value of the semaphore. Consider the following (correct) implementation of setlock: [0] CLI ;disable ints [1] RETRY: [2] CMPI LOCKVAL, 0 ;see if its 0 [3] JNZ RETRY ;if not, keep trying til it is. [4] TS LOCKVAL ;use the hardware to make sure. [5] JNZ RETRY ;start over if we got beat to the lock [6] RET 12. If statements [4] and [5] were removed which of the following BEST describes the result in a multiprocessor system. a. it would no longer work b. it would still work correctly correctly and but it would but it would be slower. be faster. c. it still work correctly and it would be faster. 13. If statements [4] and [5] were removed which of the following BEST describes the result in a single processor system: a. it would no longer work b. it would still work correctly correctly and but it would but it would be slower. be faster. c. it still work correctly and it would be faster. 14. Consider the following implementation of unlock: [0] STI ;Turn ints back on [1] MOVI LOCKVAL,0 ;Reset the lock value. a. The statements are in the b. The statements are in the WRONG order. correct order c. The order of the statements is irrelevant. 15. If interrupts are not disabled while attempting to acquire a test and set lock in a system that uses strict priority scheduling a. Processes may deadlock in b. Processes may deadlock single processor system in both single and multiple but not in an MP system. processor systems but the likelihood of deadlock is greater on a single processor c. Processes may deadlock d. Processes may deadlock in in both single and multiple a mulitple processor system processor systems but the but not in a single processor. likelihood of deadlock is greater on a multiprocessor 16. When a correct implementation of wait that contains disablement and test and set is used, the TS instruction will always succeed: a. On the first try on both b. On the first try on single CPU single and multiple processor system but not necessarily systems. on multiple processor systems. c. On the first try on single CPU d. Never on either single or system but never mulitiple processor systems. on multiple processor systems. 17. Answer the following questions T or F: ___ a. The amount of CPU time consumed by a process while it was swapped out is an important factor in determining which process to swap in. ___ b. It is generally more desirable to swap out processes that are suspended than processes that are ready to run. ___ c. A process should always be swapped back in after a fixed amount of time regardless of whether it is in the ready or suspended state. ___ d. A process should be swapped out each time it is suspended to wait for the completion of a disk i/o operation. 18. Consider the following code segment from a bounded buffer producer consumer problem; Producer Consumer wait(mutex); wait(mutex); wait(slot); wait(item); buffer[nxt_in] = new_item; consume = buffer[nxt_out]; nxt_in = (nxt_in + 1) % BUFSZ; nxt_out = (nxt_out + 1) % BUFSZ; signal(item); signal(slot); signal(mutex); signal(mutex); a. Is the order of the waits in the above example correct? (yes/no) b. Now suppose the the order of the waits in the CONSUMER code were reversed but LEFT AS THEY APPEAR in the producer code. In this case a deadlock could occur: 1. Only when the buffer was 2. Only when the buffer empty. was full. 3. Any time to buffer was either 4. Anytime regardless of the full or empty. state of the buffer. c. The deadlock could occur: 1. Only if there were multiple 2. Only if there were multiple consumers. producers 3. Only if there were multiple 4. Even if there were a single producers AND consumers. producer and consumer. d. Can changing the order of the signal statements lead to deadlock if the producers and consumers all use the same mutex semaphore. 1. No, never 2. Yes, definitely 3. Only when multiple producers or consumers exist. 19. Write the locking part (the part that appears BEFORE the READ();) of the reader priority solution to the readers and writers problem.