



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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Exam; Class: Operating Systems; Subject: Computer Science; University: Wichita State University; Term: Fall 2004;
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!
CS 540 Operating Systems Test 1 - Name: Date: Friday, October 15, 2004 (in class)
Part 1: (36 points - 3 points for each problem)
( D ) 1. Which statement is false? (A) An operating system is used to manage all devices. (B) In UNIX I/O devices are treated as special files. (C) The core part of the operating system is called kernel. (D) None of the above
( B ) 2. Which POSIX system call replaces a process’ core image? (A) fork (B) execv (C) run (D) None of the above
( A ) 3. Which statement about processes is false? (A) A process information is stored in the process data block. (B) A process can generate child processes. (C) Two processes can be connected by a pipe. (D) None of the above
( C ) 4. Which is not the benefit of using threads? (A) Responsiveness (B) Economy (C) Fairness (D) None of the above
( A ) 5. Which statement about kernel and user-level threads is true? B (A) Both kernel and user-level threads share signals. (B) Both kernel and user-level threads have their own program counter, stack, and registers. (C) kernel thread scheduling is faster than user-level thread scheduling. (D) None of the above
( D ) 6. Which of the following instructions can be run in user mode? (A) Disable all interrupts. (B) Set the time-of-day clock. (C) Change the memory map. (D) None of the above
( B ) 7. Which scheduler decides the degree of multiprogramming? (A) Admission scheduler (B) Memory scheduler (C) CPU scheduler (D) None of the above
( C ) 8. Which is not a CPU scheduling criterion? (A) CPU utilization (B) Response time (C) Reliability (D) None of the above
( C ) 9. Which is not a preemptive scheduling? (A) RR (B) SRTN (C) SJF (D) None of the above
( A ) 10. Which scheduling algorithm is better for an interactive system? (A) RR (B) SRTN (C) SJF (D) None of the above
( D ) 11. Which cannot be used to solve the critical-region problem? (A) Test And Set Lock (B) Monitor (C) Message passing (D) None of the above
( B ) 12. The aging algorithm with a = 1/2 is being used to predict run times. The previous 3 runs, from oldest to most recent, are 20, 40, and 20 msec. What is the prediction of the next time? (A) 20 (B) 25 (C) 30 (D) None of the above
Part 2: (64 points)
(a) Mutual exclusion is guaranteed. (b) Progress is maintained. No process running outside its critical region may block other processes. (c) Bounded waiting is assured. No process should have to wait forever to enter its critical region. (d) No assumptions are made about the speeds of processes or the number of processors (CPUs).
(a) (2 pts.) What is a shell? Ans: A shell is a process that reads commands from a terminal.
(b) (2 pts.) What is a daemon? Ans: A process running in the background to handle some activity is called daemon.
(c) (3 pts.) What are three process states? Ans: running, ready, blocked.
(d) (2 pts.) What is a race condition? Ans: The race condition is the situation where several processes access and manipulate shared data concurrently. The final value of the shared data depends upon which process finishes last.
DOWN(S): while (S <= 0) /* do nothing */ ; S = S - 1;
UP(S): S = S + 1;
Assume that the operations are executed atomically (however, a process may be preempted at the beginning of the while loop if (S <= 0)). A solution to the mutual exclusion problem, using these operations is shown below:
shared int S = 1; /* S is initialized to 1 */
Each process executes the following code:
while (TRUE) { DOWN(S);
(a) Does the above solution involve any busy-waiting? Explain. (b) What is the ”priority inversion” problem? (c) If priority scheduling is used, can the above solution lead to the priority inversion problem? If so, give an example; otherwise, explain why not. (d) If wait and signal are not executed atomically, what property of a good solution may be violated? Give an example.
Ans:
(a) This semaphore definition involves the busy waiting because a waiting process is looping for the shared variable S. (b) A priority inversion problem is a situation in which a low-priority process is blocking a high- priority process. (c) Yes, the above solution can lead to the priority inversion problem if a high-priority process is waiting for a low-priority process to leave the critical section and signal the shared variable S. (d) The mutual exclusion is violated. When process A is in the while loop, the context switch happens. Process B could enter the critical region after executing the while loop and S = S - 1. Then another context switch happens. Process A could enter the critical region after executing S = S - 1.
Process Run Time Priority A 4 2 B 2 3 = low C 3 1 = high
(a) Draw four Gantt charts illustrating the execution of these processes using FCFS, SJF, a nonpre- emptive priority (a smaller priority number implies a higher priority), and RR (quantum = 2) scheduling. (b) What is the waiting time of each process for each of the scheduling algorithms? (c) What is the turnaround time of each process for each of the scheduling algorithms?
Ans:
(a) The four Gantt charts are +---+--+----+ +--+---+----+ | A | B| C | FCFS | B| C | C | SJF +---+--+----+ +--+---+----+ 0 4 6 9 0 2 5 9
+---+----+--+ +--+--+--+--+-+ | C | A | B| Priority |A | B| C| A|C| RR +---+----+--+ +--+--+--+--+-+ 0 3 7 9 0 2 4 6 8 9 (b) Waiting time:
| FCFS | SJF | Priority | RR ---+------+-----+----------+---- A | 0 | 5 | 3 | 4 B | 4 | 0 | 7 | 2 C | 6 | 2 | 0 | 6 (c) Turnaround time: | FCFS | SJF | Priority | RR ---+------+-----+----------+---- A | 4 | 9 | 7 | 8 B | 6 | 2 | 9 | 4 C | 9 | 5 | 3 | 9
A \ mbox
mbox1 C / \ mbox B / \ E \ / mbox2 \ / mbox D
The program can be as follows:
read(mbox1, msg); /* Block until A finished / read(mbox1, msg); / Block until B finished */
read(mbox2, msg); /* Block until B finished */
read(mbox3, msg); /* Block until C finished / read(mbox3, msg); / Block until D finished */