0% found this document useful (0 votes)
45 views16 pages

CS311 Exam

The document is a 15 page exam for an operating systems course containing 12 questions. It covers topics like layered system design, I/O techniques, system calls, resource allocation graphs, deadlocks, philosophers problem, synchronization, scheduling algorithms, paging, file allocation strategies, memory management schemes, and mutual exclusion.

Uploaded by

p8rk6rp7wd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views16 pages

CS311 Exam

The document is a 15 page exam for an operating systems course containing 12 questions. It covers topics like layered system design, I/O techniques, system calls, resource allocation graphs, deadlocks, philosophers problem, synchronization, scheduling algorithms, paging, file allocation strategies, memory management schemes, and mutual exclusion.

Uploaded by

p8rk6rp7wd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

eusP

THE UNIVERSITY OF THE


SOUTH PACIFIC

CS311: Operating Systems


Faculty of Science, Technology and Environment
School of Computing, Information and Mathematical Sciences

Final Examination
Semester 1 2019

F2F Mode

Duration of Exam: 3 hours+ 10 minutes

Reading Time: 10 minutes

Writing Time: 3 hours

Total Marks: 100

Instructions:

Answer all questions in this paper

This exam is worth 45% of your overall mark

The minimum mark to pass the final exam is 18/45

The total number of pages including this cover sheet is 15

This is a closed book exam

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

Allocation Maximum Demand


Process rl r2 r3 rl r2 r3
Pl 0 1 0 7 s 3
P2 2 0 0 3 2 2
P3 3 0 ·2 9 0 2
P4 2 1 1 2 2 2
PS 0 0 2 4 3 3

a) Compute the matrix Need. (2 marks)

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

Allocation Maximum Request


Demand
Process rl r2 r3 rl r2 r3 Rl R2 R3
Pl 0 1 0 0 1 0 0 0 0
P2 2 0 0 3 0 1 1 0 0
P3 1 2 0 2 5 2 0 0 1
P4 0 1 1 1 4 2 0 0 0
PS 0 0 1 2 0 1 0 0 1

a) Draw the resource allocation graph of the above system. (S marks)

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:

ThreadO () { Threadl () { Thread2() { Thread3() { r:fhread4 () {


for(;;) { for(;;) { for(;;) { for(;;) { for(;;) {
think(); think(); think(}; think(); think();
wait(&fO); wait (&fl); wait(&f2); wait(&f3); wait(&f4);
wait(&fl); wait(&f2); wait(&f3); wait(&f4); wait(&fO);
eat(); eat(); eat(); eat(); eat();
signal(&fl); signal(&f2); signal(&f3); signal(&f4); signal(&fO);
signal(&fO); signal(&fl); signal(&f2); signal(&f3); signal(&f4);
} } } } }
} } } } }

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)

II Global variables and semaphores


sema4 t a O;
sema4 t b = O;

void Thread.A(void) { void ThreadB(void) {

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.

Process Burst Time


Pl 7
P2 1
P3 2
P4 5
PS 3

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.

int status[2]; // status of a process .;,

int turn; // initialized to either O or 1

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

Process Address Page# Offset Physical


address
Process 1 11034
Process 2 12345

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

• First Come First Serve (2 marks)


• Shortest Seek First (2 marks)

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

You might also like