PROJECTENGRAM

[QZ] CSOPESY MIDTERM MOCK EXAM

Tags: #◇Computer Science #◇CSOPESY #◇Operating Systems #◇Reviewer #◇Finals #◇Quiz


CSOPESY Midterm Mock Exam

◇Cover Sheet

Course: CSOPESY — Operating Systems
Coverage: Weeks 1-8 (Modules 1-3)
Format: Part I — Multiple Choice (25 pts) | Part II — Problem Solving (35 pts) | Total: 60 pts
Instructions: This is a timed mock. Set a timer for 75 minutes before starting. Do not refer to your notes until after completing all sections.



◇Part I: Problem Solving (35 points)


Problem 1: CPU Scheduling (25 pts)

Given the following set of processes:

ProcessArrival Time (AT)Burst Time (BT)Priority (1 = Highest)
P1062
P2241
P3484
P4533
P5655

For each of the following four algorithms, draw the Gantt chart and compute the CT, TAT, WT per process and the Average Waiting Time:

(a) First-Come First-Served (FCFS) — 6 pts

(b) Non-Preemptive Priority Scheduling (lower number = higher priority) — 6 pts

(c) Shortest Remaining Time First (SRTF) — 7 pts

(d) Round Robin with time quantum q=2q = 2 — 6 pts

Formulas:
TAT=CT−ATWT=TAT−BTAvg WT=∑WTinTAT = CT - AT \qquad WT = TAT - BT \qquad Avg\ WT = \frac{\sum WT_i}{n}


Problem 2: Effective Access Time (5 pts)

A system uses a two-level cache-to-memory hierarchy with the following parameters:

  • Cache hit rate: H=0.92H = 0.92
  • Cache access time: Tc=5T_c = 5 ns
  • Main memory access time: Tm=200T_m = 200 ns
  • Access model: Sequential (memory is accessed only on a cache miss, after the cache lookup completes)

(a) Using the EAT formula, compute the Effective Access Time. Show your work. (3 pts)

EAT=H×Tc+(1−H)×(Tc+Tm)EAT = H \times T_c + (1-H) \times (T_c + T_m)

(b) If the cache hit rate improves to H=0.99H = 0.99, compute the new EAT. (2 pts)


Problem 3: Amdahl's Law (5 pts)

A parallel image-processing application is profiled. Analysis reveals that 30% of its execution is inherently sequential (cannot be parallelized — reading input, writing output, and maintaining state). The remaining 70% can be distributed across any number of cores.

(a) Using Amdahl's Law, compute the maximum theoretical speedup with N=4N = 4 processor cores. Show your work. (3 pts)

Speedup≤1S+1−SNwhere S=sequential fractionSpeedup \le \frac{1}{S + \frac{1-S}{N}} \qquad \text{where } S = \text{sequential fraction}

(b) As the number of cores approaches infinity (N→∞N \to \infty), what is the absolute maximum speedup this application can theoretically achieve? What does this imply about the value of simply adding more cores? (2 pts)



◇Problem Solving Answer Key

Problem 1 Solutions

Process Table:

ProcessATBTPriority
P1062
P2241
P3484
P4533
P5655

(a) FCFS

Gantt Chart:

『』
TIMELINE // GANTT
P16ms
0
P24ms
6
P38ms
10
P43ms
18
P55ms
21
26
PATBTCTTATWT
P106660
P2241084
P34818146
P453211613
P565262015

Avg WT: (0+4+6+13+15)/5=38/5=7.6(0 + 4 + 6 + 13 + 15) / 5 = 38 / 5 = \mathbf{7.6} ms


(b) Non-Preemptive Priority (1 = Highest)

Selection logic:

  • t=0: Only P1 (pri=2) → run P1 (0→6, CT=6)
  • t=6: Available: P2(1), P3(4), P4(3), P5(5) — all arrived by t=6. Highest: P2(1) → 6→10
  • t=10: Available: P3(4), P4(3), P5(5). Highest: P4(3) → 10→13
  • t=13: Available: P3(4), P5(5). Highest: P3(4) → 13→21
  • t=21: Only P5(5) → 21→26

Gantt Chart:

『』
TIMELINE // GANTT
P16ms
0
P24ms
6
P43ms
10
P38ms
13
P55ms
21
26
PATBTCTTATWT
P106660
P2241084
P34821179
P4531385
P565262015

Avg WT: (0+4+9+5+15)/5=33/5=6.6(0 + 4 + 9 + 5 + 15) / 5 = 33 / 5 = \mathbf{6.6} ms


(c) SRTF (Preemptive SJF)

Event-by-event trace:

TimeEventCPU (rem)Action
t=0P1 arrives (6)P1(6)Start P1
t=2P2 arrives (4). P2(4) = P1 rem(4) → tie, no preemptP1(4), P2(4)Continue P1
t=4P3 arrives (8). P3(8) > P1 rem(2) → continueP1(2), P2(4), P3(8)Continue P1
t=5P4 arrives (3). P4(3) > P1 rem(1) → continueP1(1), P2(4), P3(8), P4(3)Continue P1
t=6P1 done. P5 arrives (5). Queue: P2(4), P3(8), P4(3), P5(5). Shortest: P4(3)—Start P4
t=9P4 done. Queue: P2(4), P3(8), P5(5). Shortest: P2(4)—Start P2
t=13P2 done. Queue: P3(8), P5(5). Shortest: P5(5)—Start P5
t=18P5 done. Only P3(8)—Start P3
t=26P3 done——

Gantt Chart:

『』
TIMELINE // GANTT
P16ms
0
P43ms
6
P24ms
9
P55ms
13
P38ms
18
26
PATBTCTTATWT
P106660
P22413117
P348262214
P453941
P56518127

Avg WT: (0+7+14+1+7)/5=29/5=5.8(0 + 7 + 14 + 1 + 7) / 5 = 29 / 5 = \mathbf{5.8} ms


(d) Round Robin (q = 2)

Queue trace (convention: new arrivals at quantum boundary join before re-queued process):

TimeRunRem AfterQueue After
0→2P1P1(4)[P2, P1] — P2 at t=2
2→4P2P2(2)[P1, P3, P2] — P3 at t=4
4→6P1P1(2)[P3, P2, P4, P5, P1] — P4 at t=5, P5 at t=6
6→8P3P3(6)[P2, P4, P5, P1, P3]
8→10P2DONE (CT=10)[P4, P5, P1, P3]
10→12P4P4(1)[P5, P1, P3, P4]
12→14P5P5(3)[P1, P3, P4, P5]
14→16P1DONE (CT=16)[P3, P4, P5]
16→18P3P3(4)[P4, P5, P3]
18→19P4DONE (CT=19)[P5, P3]
19→21P5P5(1)[P3, P5]
21→23P3P3(2)[P5, P3]
23→24P5DONE (CT=24)[P3]
24→26P3DONE (CT=26)—

Gantt Chart:

『』
TIMELINE // GANTT
P12ms
0
P22ms
2
P12ms
4
P32ms
6
P22ms
8
P42ms
10
P52ms
12
P12ms
14
P32ms
16
P41ms
18
P52ms
19
P32ms
21
P51ms
23
P32ms
24
26
PATBTCTTATWT
P106161610
P2241084
P348262214
P453191411
P565241813

Avg WT: (10+4+14+11+13)/5=52/5=10.4(10 + 4 + 14 + 11 + 13) / 5 = 52 / 5 = \mathbf{10.4} ms


[!note] Algorithm Comparison Summary

AlgorithmAvg WT
SRTF5.8 ms (best)
Non-Preemptive Priority6.6 ms
FCFS7.6 ms
Round Robin (q=2)10.4 ms

SRTF minimizes average waiting time. RR with a small quantum performs worst here due to high context switch turnover across 5 processes.


Problem 2 Solution: EAT

(a) H = 0.92:

EAT=H×Tc+(1−H)×(Tc+Tm)EAT = H \times T_c + (1-H) \times (T_c + T_m)
=0.92×5+0.08×(5+200)= 0.92 \times 5 + 0.08 \times (5 + 200)
=4.6+0.08×205= 4.6 + 0.08 \times 205
=4.6+16.4=21.0 ns= 4.6 + 16.4 = \mathbf{21.0 \text{ ns}}

(b) H = 0.99:

EAT=0.99×5+0.01×205EAT = 0.99 \times 5 + 0.01 \times 205
=4.95+2.05=7.0 ns= 4.95 + 2.05 = \mathbf{7.0 \text{ ns}}

Insight: Improving cache hit rate from 92% to 99% cuts EAT by 67% (21.0 → 7.0 ns), underscoring why CPU designers invest heavily in cache design.


Problem 3 Solution: Amdahl's Law

(a) N = 4 cores, S = 0.30:

Speedup≤10.30+0.704=10.30+0.175=10.475≈2.11xSpeedup \le \frac{1}{0.30 + \frac{0.70}{4}} = \frac{1}{0.30 + 0.175} = \frac{1}{0.475} \approx \mathbf{2.11x}

(b) N → ∞:

Speedupmax=1S+0=10.30≈3.33xSpeedup_{max} = \frac{1}{S + 0} = \frac{1}{0.30} \approx \mathbf{3.33x}

Implication: No matter how many cores are added, the maximum speedup is capped at 3.33x because 30% of the application is sequential and cannot be parallelized. Adding cores beyond a certain point yields negligible returns — the sequential bottleneck becomes the only limiting factor. This is why optimizing the sequential portion (reducing SS) is often more impactful than simply adding more hardware.


◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

An operating system is best described as which of the following from the System View perspective?

Q2

Hardware provides a mechanism to prevent user programs from executing instructions like halting the CPU or directly accessing another process's memory. What hardware feature enables this protection?

Q3

A system checks its L1 cache first. On a miss, it then accesses main memory. Given H=0.95H = 0.95, Tc=4T_c = 4 ns, and Tm=200T_m = 200 ns, compute the Effective Access Time (EAT) using the sequential access model.

EAT=H×Tc+(1−H)×(Tc+Tm)EAT = H \times T_c + (1-H) \times (T_c + T_m)

Q4

A Zombie process differs from an Orphan process in that:

Q5

A device controller for a high-speed NVMe SSD transfers 1 MB of data to RAM. The OS uses DMA. How many CPU interrupts does this transfer generate?

Q6

A read() call on a socket returns immediately with EAGAIN. The calling thread continues executing other code and re-checks the socket after completing its UI update. Which I/O model does this exemplify?

Q7

Which of the following is a User Service provided by the OS, as opposed to a System Efficiency Service?

Q8

In the program build pipeline — Source → Compiler → Assembler → [X] → Loader — what does component [X] do?

Q9

A Monolithic Kernel has a buggy device driver for a new graphics card. What is the most likely system-level consequence?

Q10

According to Amdahl's Law, an application has 20% sequential code (S=0.20S = 0.20) and 80% parallelizable code. With N=8N = 8 processors, what is the maximum achievable speedup?

Speedup≤1S+1−SNSpeedup \le \frac{1}{S + \frac{1-S}{N}}

Q11

Thread A and Thread B both share a global integer total. Both threads read total = 100, increment it, and write back. After both complete, total = 101 instead of 102. This is caused by:

Q12

A thread calls wait(S) on a semaphore SS initialized to 0. What happens to the calling thread?

Q13

Process P1 holds Lock A and requests Lock B. Process P2 holds Lock B and requests Lock A. Both are suspended, waiting indefinitely. Which necessary condition for deadlock does this most directly demonstrate?

Q14

A Round Robin scheduler uses a very small time quantum (e.g., 1ms). What is the primary performance concern?

Q15

Which CPU scheduling criterion measures the total elapsed time from when a process is submitted to when it completes — including all waiting and execution time?

Q16

Under SRTF (Shortest Remaining Time First), which process will be selected next from the ready queue at the given snapshot?

ProcessRemaining Burst
P16 ms
P22 ms
P34 ms
P49 ms
Q17

A POSIX thread is created with pthread_create(). The main thread then calls pthread_join(). What does pthread_join() do?

Q18

Memory-Mapped I/O means that:

Q19

A web browser uses one thread for the UI, one for network requests, and one for JavaScript execution — all within the same browser process. If the network thread blocks waiting for a server response, what happens in a One-to-One threading model?

Q20

A spooler daemon intercepts print jobs from multiple applications, queues them to disk, and sends them to the printer one at a time. Which kernel I/O service is this?

Q21

The process of saving a currently running process's register state and program counter into its PCB, then loading the next process's PCB to resume it, is called:

Q22

In Peterson's Solution for the Critical Section Problem, two shared variables are used: flag[2] and turn. What does setting flag[i] = true signify?

Q23

Which of the following best describes Thread-Local Storage (TLS)?

Q24

The fork() system call returns a different value to the parent and child process. What does fork() return to the parent process?

Q25

Non-preemptive Priority Scheduling without aging can result in which of the following problems?