Computer Science 422/622 Test 1 - 23 Feb 2001 Name________________________ 1. We studied a process state transition diagram that included the states running, ready, and suspended. Each of the following actions is causes a state transition. For each identify the original state and the destination state of the process that makes a transition. Original state Destination state | a. Unsuspend susp | rdy ---------------------|--------------------- 6 | b. Suspend_Self run | susp ---------------------|--------------------- | c. Preempt run | rdy ---------------------|--------------------- 2. When an interrupt occurs the Pushing of the IP and Flags registers onto the stack is performed by: a. The interrupted application b. The O/S c c. By the hardware w/o O/S or application involvement 3. The interrupt address table (which contains the address of interrupt handlers) is constructed by: a. Application programs b. The O/S at boot time b c. Automatically by the hardware d. By the O/S each time a process is dispatched 4. The mechanism used to effect a transfer of control from a running application to the operating system is: a. a subroutine call b. an interrupt instruction b c. an iret instruction d. Both (a.) and (b.) are used interchangably 5. In the multitasking model that we discussed in class, OS code runs: a. each time a switch between b. only after all tasks have a two application tasks occurs. had a chance to run. c. after each instruction is d. only when there are no executed by an application. applications available to run. 6. Which of the following state transitions would be made MOST OFTEN by a process that did a tremendous amount of computation but no I/O at all. a a. Running to Ready b. Blocked to Ready c. Running to Blocked d. Running to zombie 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] while(using[other]); [4] using[me] = 1; [5] return; } 7. The above solution is: a. Livelock prone b. Unsafe b c. Deadlock prone d. All of the above 8. The problem a. will occur EVERY time a b. may occur if a process is preempted process gets preempted between lines [3] and [4] (but can b 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]. 9. If lines [3] and [4] are interchanged the "solution" becomes: a. Livelock prone b. Unsafe c c. Deadlock prone d. Correct 10. The above solution is: a. Livelock prone b. Unsafe c. Deadlock prone d. Requires strict turn taking 11. The problem a. will occur EVERY time a b. may occur if a process is preempted process gets preempted 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]. 12. If lines [3] and [4] are interchanged the "solution" becomes: a. Livelock prone b. Unsafe c. Deadlock prone d. Correct Consider the following (correct) solution to the mutual exclusion problem int using[2]; int turn; void pete_lock(int pid) /* Pid = 0 or 1 */ { int me, other; [1] me = pid; [2] other = me ^ 1; [3] using[me] = 1; [4] turn = other; [5] while(using[other] && turn == other); [6] return; 13. If lines [3] and [4] are interchanged the "solution" becomes: a. Livelock prone b. Unsafe b c. Deadlock prone d. Remains safe 14. If we modify the original correct solution so that line [4] reads turn = me (but line [5] stays the same) the solution becomes: a. Livelock prone b. Unsafe b c. Deadlock prone d. Remains safe 15. Answer the following questions T or F: _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. 6 _T_ b. It is generally more desirable to swap out processes that are suspended than processes that are ready to run. _F_ c. A process should be swapped out each time it is suspended to wait for the completion of a disk i/o operation. 16. Suppose PS == (no overhead RR) scheduling is used and four jobs are started at the same time. Two of the jobs require 3 hours of CPU time, one requires 6 hours, the other requires 7 hours. a. How long after the jobs start will the FIRST job(s) finish. 12 2 b. How long after the jobs start will the last job finish. 2 19 c. What is the average response time for the four jobs (with PS) scheduling. 2 (12 + 12 + 18 + 19) / 4 d. What is the average response time if the SJF (Shortest job first non-preemptive scheduling policy is used 2 (3 + 6 + 12 + 19) / 4 17. Suppose 2 processes are to be run and EACH ONE requires 6 minutes of processor time and 9 minutes of disk time. Suppose they are run on an ideal multitasking system in which the best possible overlap of CPU and disk activity is achieved with no OS overhead at all. a. If they both start at the same time, how long will it be until they both finish? 1. 6 minutes 2. 9 minutes 3. 15 minutes x 4. None of the above b. What percentage of the total run time will the CPU be BUSY. 1. 100% 2. 50% 3. 33% x 4. None of the above Suppose a small transaction processing system is being run on a personal computer class system. Each transaction requires 0.10 seconds of CPU time and 0.25 seconds of disk time. 18. What is the maximum throughput in transactions per second a. 25 b. 5 c c. 4 d. None of the above 19. What is the minimum response time in seconds (assuming a single transaction cannot overlap its own Disk and CPU processing) a. 0.10 b. 0.35 b c. 0.25 d. None of the above 20. Suppose the following code segment is executed and the child"n" functions RETURN INSTEAD OF EXITING. How many total processes (EXCLUDING the original parent will be created?) if (fork() == 0) child1(); if (fork() == 0) child2(); c if (fork() == 0) child3(); a. 3 b. 6 c. 7 d. None of the above 21. Consider the following code segment: int a = 0; |---> for (c = 0; c < 100000; c++) void xthread( | a = a + 1; int x, | int y) | } { | int c, d; --------- Suppose two threads are created and both run the function xthread which of the following BEST characterizes the sharing of data. a. The variable 'a' is shared b. 'a' and 'x' are shared but but both threads have private 'c' is private. copies of 'x' and 'c'. a c. All five variables are shared d. all five variables are private. (i.e. if either thread changes one of them, the change is seen by the other thread. 22. Suppose the above function is run concurrently as 4 separate threads. After all threads complete the value of "a" will be: a. somewhat less than 400000 b. somewhat greater than 400000 or possibly even equal to or possibly even equal to a 400000 400000 c. exactly 100000 d. exactly 400000 Recall the program discussed in class .. child1 wrote into a pipe and child2 read from it. void main(void) { int pipeids[2]; int pid; int status; pipe(pipeids); /* close(pipeids[1]); */ if (fork() == 0) { child1(pipeids); } /* close(pipeids[1]) */ if (fork() == 0) { child2(pipeids); } /* close(pipeids[1]) */ wait(0); wait(0); 23. In the program segment above, which instance of close() call should be uncommented in order for the program to work correctly and for child2 to get EOF on the pipe when child one executes close(pipeids[1]); b a. The first one b. The second one c. The third one d. All work equally well 24. Suppose that the call to the pipe() function was moved from its present location to a spot immediately before the 2nd close(). Which of the following best characterizes the resulting situation: a. The program will continue b. Two pipes will now be created and to work just as before communication between the children remains possible using either one. d c. Two pipes will be created d. Two pipes will be created and and communication between communication between the children children remains possible will not be possible using either using the pipe created by one. the parent. 25. 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 and conditions such as MAX_INT being reached)) _T_ a. A signal operation on a semaphore which has an empty wait queue always causes the value of the semaphore to be incremented. _F_ b. A semaphore that has the value 0 always has at least 8 one suspended process. _T_ c. A signal operation on a semaphore that has a value of 0 may OR may not cause the value to be incremented. _T_ d. A wait operation on a semaphore with a non-empty wait queue never changes the value of the semaphore. 26. When a new thread is created using pthread_create, execution of the new thread begins at: a. the point of return from b. Back at the start of the c thr_create (like fork) function that called thr_create c. At the start of the function d. At the main() function in the specified in thr_create new a.out specifed in thr_create