CS311 Exam
CS311 Exam
Final Examination
Semester 1 2019
F2F Mode
Instructions:
Page 1 of 15
1. Explain the advantages and disadvantages of layered approach to system design. (4 marks)
2. Compare 1/0 based on polling with interrupt-driven 1/0. In what situation would you favor one
technique over the other? (4 marks)
3. Using a simple system call as an example (e.g. getpid, or uptime), describe what is generally
involved in providing the result, from the point of calling the function in the C library to the point
where that function returns. (4 marks)
Page 2 of 15
4. Consider the following snapshot of a system with five processes (Pl, P2, P3, P4, PS) and three
resources (rl, r2, r3).
Available Resources
rl r2 I r3 I
3 13 12
b) Explain whether the system is in a safe state? If it is, provide the sequence of how processes
will finish. If not, explain why. (3 marks)
Page 3 of 15
c) If a request from P4 arrives for (2, 3, O), can that request be safely granted? Show all
working. (3 marks)
5. Consider the following information about resources and processes in the system.
Available Resources
rl r2 r3
0 2 0
Page 4 of 15
b) Is this system deadlocked? If yes, state which processes are deadlocked. If not, provide
execution sequence. (2 marks)
6. Assume five philosophers are sitting at a round table with five plates and five forks. The
philosophers continuously alternate between eating and thinking. To eat, a philosopher needs
two forks. The synchronization problem is that each fork can only be held by one philosopher at
a time. The goal is to find a solution in which it is guaranteed that no philosopher will starve, while
allowing as many philosophers to eat at the same time as possible. Given the following coding of
this problem in which philosophers are represented by threads and forks represent shared
resources protected by semaphores:
Is this a valid solution to the problem that satisfies all constraints? If yes, prove it. It no, explain
why not (provide a counterexample), and show modified code that provides a valid solution. (7
marks)
Page 5 of 15
7. Consider a problem in which we want to synchronize two foreground threads such that each
thread can only proceed beyond a certain point once it is guaranteed that the other thread has
also arrived at its synchronization point. This is called a rendezvous pattern. In other words, using
only semaphores and regular C statements/variables, complete the following code such that a2()
executes after bl(), and b2() executes after al(): (5 marks)
al () ; bl () ;
//rendezvous here //rendezvous here
a2 () ; b2 () ;
} }
Page 6 of 15
8. Consider the following set of processes ready to be scheduled on a single CPU system. Assume
processes arrived in numerical order at time 0.
a) Draw a gantt chart and calculate turnaround time for the FCFS scheduling algorithm. (2 marks)
b) Draw a gantt chart and calculate turnaround time for the preemptive shortest job first
algorithm. (2 marks)
c) Draw a gantt chart and calculate turnaround time for the round robin algorithm (quantum =
1). (2 marks)
Page 7 of 15
9. Consider a system with four physical memory frames that are initially empty and the page
references given below.
0011012212331440021121404051
Show which references cause page faults and show which pages are in which frames at
the end of the sequence of references using FIFO and LRU. Assume that when there
are empty frames, pages are loaded into the lowest available frame. There are four
frames in the memory.
a) How many page faults will be there if FIFO page replacement policy is used? Show all
working. (2 marks)
b) How many page faults will be there if LRU page replacement policy is used? Show all
working. (2 marks)
Page 8 of 15
10. Suppose a file system can have three disk allocation strategies, contiguous, linked, and indexed.
We have just read the information for a file from its parent directory. For contiguous and linked
allocation, this gives the address of the first block, and for indexed allocation this gives the address
of the index block. Suppose that file is spread over 20 data blocks. Now we want to read the 12th
data block into the memory. How many disk blocks do we have to read for each ofthe allocation
strategies to read 12th data block? Explain your answer in each case. (6 marks)
11. Explain external and internal fragments. Consider the following memory management schemes:
fixed-size partitions, variable-size partitions, and paging. Which schemes have external fragments,
and which schemes have internal fragments? (4 marks)
Page 9 of 15
12. Consider the following solution to the mutual exclusion problem for two processes PO and Pl,
where status[] is a Boolean array of two elements and turn is an integer variable. Furthermore,
there are three constants indicating the status of a process, where COMPETING, IN_CS and
OUT_CS mean competing to enter the critical section, in the critical section, and out of the critical
section. Note that status[] and turn are global variables shared by both processes.
Process 0 Process 1
-------- ========
1 status[O] = COMPETING; status[l] = COMPETING;
2 while (status[l] == COMPETING) while (status[O] == COMPETING)
3 status[O] = OUT_CS; status[l] = OUT_CS;
4 repeat until (turn== 0); repeat until (turn== 0 I I turn -- l);
5 turn = O; turn= l;
6 status[O] = COMPETING; status[l] = COMPETING;
7
// critical section
8 status[O] = OUT_CS; status[l] = OUT_CS;
9 turn = O; turn = O;
Explain whether the above solution satisfies mutual exclusion. Show execution sequence and
explain your answer. (5 marks)
Page 10 of 15
13. A paging system uses 16-bit address and 4K pages. The following shows the page tables of two
running processes, Process 1 and Process 2. Translate the logical addresses in the table below to
their corresponding physical addresses, and fill the table entries with your answers. (4 marks)
~§ ~§2
Process 1 Process 2
2 2 6
3 3 4
14. Explain the main difference between access list and capability list. (3 marks)
Page 11 of 15
15. Given a disk with 200 tracks, where track requests are received in the following order 55, 58, 39,
18, 90, 160, 150, 38, 184. The starting position for the arm is track 100. Calculate the number of
tracks crossed when the following algorithms are used
16. How does OMA increase system concurrency? How does it complicate hardware design? (4 marks)
Page 12 of 15
17. Use state diagram to show all the state transitions of the parent process during the entire
execution of the following program. Use the line numbers to indicate the transitions that take
place. (6 marks)
1. int main()
2. {
3. int pid;
4. pid = fork () ;
5. if (pid == 0)
6. {
7. cout << "Iam Child Process\n";
8. }
9. else
10. {
11. cout << "I am Parent Process\n"
12. wait(NULL);
13. }
14. return 0;
15.}
Page 13 of 15
18. Why is it difficult to protect a system in which users are allowed to do their own 1/0? (3 marks)
19. How do caches help improve performance? Why do systems not use more or larger caches if they
are so useful? (4 marks)
Page 14 of 15
20. Describe the relationship between an API, the system-call interface, and the operating system. (4
Marks)
21. Explain why a modular kernel may be the best of the current operating system design techniques.
(4 Marks)
The End
Page 15 of 15