You are on page 1of 15

HONG KONG BAPTIST UNIVERSITY

Page: 1
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

Instructions
1. This is a closed book examination.
2. Write down your name and student ID number at the top right corner of each page.
3. Answer all questions. Write down your answer in the space following each question.
4. At the end, scan your handwritten answers into a PDF file and upload this PDF file to
HKBU Moodle (please select “COMP2017 (1) [2021 S2]” and “Upload Link for Final
Exam”)

Questions

1(a) Suppose you plan to purchase a new computer with an Intel i9 CPU for big data
computing (i.e., processing a large volume of high-precision data). Give two reasons to
explain whether you would select 32-bit Windows 10 or 64-bit Windows 10 for this
new computer.
(4 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 2
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

1(b) Suppose you are developing a network game which uses the network card for Internet
communication and the display card for graphical output. Explain whether you would
run this network game in the kernel mode to control the network card and the display
card.
(4 marks)

1(c) Consider context switch.


(i) Explain why context switch is undesirable.
(2 marks)
(ii) Give two reasons to explain why context switch involves significant time.
Suggest two computer configurations for faster context switch.
(6 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 3
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

1(d) An OS applies round robin scheduling to schedule to run three threads T1, T2 and T3 on
a CPU core which supports Intel Hyper-Threading. Draw a timing diagram to show the
following: (i) execution of each thread, and (ii) saving and restoring threads’
information.
(4 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 4
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

2(a) An application program adopts both the multi-thread design and the multi-process design
and its pseudocode is given below.

void main()
{

Run Task1() as a new thread;
Run Task2() as a new thread;
Run Task3() as a new process;

Wait until Task1(), Task2() and Task3() have completed execution;

}

Draw a diagram to show the execution of this program on a quad-core CPU (assuming
that this CPU is only running the above program) and number every process and every
thread.
(4 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 5
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

2(b) The following Java program computes A = 1×2 + 2×3 + ... + 200×201 on a dual-core
CPU as follows:
• It runs a concurrent thread to compute A1 = 1×2 + 2×3 + … + 100×101.
• It runs another concurrent thread to compute A2 = 101×102 + 102×103 + … +
200×201.
• When the above two concurrent threads have completed execution, it
computes A1 + A2 and then outputs the value of A.
The program has a missing code segment (denoted by X). Write the code segment for
X.
(8 marks)
class MyThread extends Thread {
int N1, N2, sum;
public void run() {
sum=0;
for (int i=N1; i<=N2; i++) sum=sum+i*(i+1);
}
}

public class MyProgram1 {


public static void main(String[] args) throws InterruptedException {

X
System.out.printf("Total sum = %d\n", A.sum+B.sum);
}
}
HONG KONG BAPTIST UNIVERSITY
Page: 6
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

2(c) A Java program with the main() method carries out a simulation experiment. It has
been compiled to SimuExp.class, it does not accept any input parameter, and it is
stored in the folder d:\project\bin. To run this simulation experiment 100 times, the
following program creates 100 processes to run SimuExp.class 100 times respectively,
redirects their outputs to the console, waits for their completion, and then stops. The
program has a missing code segment (denoted by Y). Write the code segment for Y.
(8 marks)

public class MyProgram2 {


public static void main(String[] args) throws Exception {
System.out.printf("Start!\n");

Y
System.out.printf("Completed!\n");
}
}
HONG KONG BAPTIST UNIVERSITY
Page: 7
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

3(a) Suppose load sharing is applied in conjunction with four-level feedback queue on a
dual-core CPU.
(i) Draw a diagram to show the scheduling schematic.
(4 marks)
(ii) If the quantum size for each level is smaller, describe two consequences.
(4 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 8
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

3(b) An OS adopts round robin scheduling (with a quantum size of 50 ms) to schedule to
run the following processes on a single-core CPU. Draw a Gantt chart to show the
processor schedule.
Process Ready time (ms) Running time (ms)
A 0 100
B 50 100
C 80 50
(4 marks)

3(c) An OS adopts load sharing in conjunction with short-job-first scheduling to schedule to


run the following processes on a dual-core CPU. Draw a Gantt chart to show the
processor schedule.
Process Ready time (ms) Running time (ms)
A 0 25
B 10 20
C 20 25
D 30 30
E 40 10
F 50 5

(4 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 9
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

3(d) Suppose a multi-user OS adopts fair-share scheduling in conjunction with round robin
scheduling (the quantum duration is 100 ms). A user is running four threads A1, A2, A3
and A4, and another user is running two threads B1 and B2, where all threads are ready
at time 0 ms and every thread has a running time of 500 ms. Draw a Gantt chart to
show the processor schedule in which each of these six threads is run at least once.
(4 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 10
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

4(a) In a bank, a process transfers money among three accounts A, B and C as follows
(where A, B and C have account numbers 23456, 12345 and 45678 respectively):
lock account A;
lock account B;
lock account C;
transfer $1000 from account A to account B;
transfer $2000 from account C to account B;
unlock account A;
unlock account B;
unlock account C;

(i) Apply TestAndSet() to realize the above money transfer process.


(4 marks)

(ii) Apply semaphores to realize the above money transfer process.


(4 marks)

(iii) Modify the pseudo-code in part (a)(ii) such that the modified code would never
result in a deadlock.
(4 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 11
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

4(b) A computer has N identical units of resources and it is running four processes. The
following table shows the current resource allocation and the maximum need of
resources for each process. If the current state is safe, determine the smallest value of
N.
Process Current resource allocation (unit) Maximum need of resources (unit)
A 2 3
B 1 4
C 3 6
D 2 4
(4 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 12
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

4(c) Let there be three processes (denoted by A, B and C), two types of resources (denoted
by R1 and R2), four units of R1, and three units of R2. The following table shows the
current resource allocation and the outstanding request for each process.
Current allocation Outstanding request
Process
R1 R2 R1 R2
A 2 0 0 0
B 2 2 0 1
C 0 1 1 0
Draw a resource allocation graph to represent the current resource allocations and the
outstanding requests. Reduce this graph to determine whether there is any deadlock,
showing the intermediate steps in graph reduction.
(4 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 13
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

5(a) An OS adopts two-level paging and it is managing two processes. Draw a diagram to
show the organization of the tables involved for these two processes.
(5 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 14
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

5(b) Consider the Unix’s Second Chance Replacement Method. Suppose the memory can
store four pages and it is storing the following four pages.
Page Load Time Referenced-bit
1 1987 1
4 1997 0
6 1980 1
9 2005 1
At the current time 2022, page 10 is to be swapped in. Suppose the OS can instantly
read and update the above table. Determine the page to be replaced and the updated
table.
(4 marks)
HONG KONG BAPTIST UNIVERSITY
Page: 15
Student Name:
SEMESTER 2 EXAMINATION
Student ID No.:
2021-2022

Section
Course Code: COMP2017 Number: 1 Time Allowed: 2 Hours
Course Title: Operating Systems Total No. of Pages: 15

5(c) Microsoft NTFS stores a file in the following blocks:

(i) What is the index information for the above file?


(2 marks)
(ii) Where is the index information stored?
(2 marks)
(iii) When an application wants to access the second-to-the-last block of the file,
explain how NTFS could directly access this block.
(3 marks)

5(d) Describe four factors that would affect the speed of disk defragmentation.
(4 marks)

- End of Paper -

You might also like