2082 1

BIT204 · 2082 · 10 marks

Question Differentiate between user thread and kernel thread. Given the following information about processes, compute the average waiting time and turnaround time for FCFS and Round Robin (Quantum = 2). | Processes | CPU Burst Time | Arrival Time | |-----------|----------------|--------------| | A

Question

Differentiate between user thread and kernel thread. Given the following information about processes, compute the average waiting time and turnaround time for FCFS and Round Robin (Quantum = 2).

ProcessesCPU Burst TimeArrival Time
A92
B111
C10
D23
E74

[2+8]

Operating SystemsChapter 5: Concurrency and SynchronizationUser level threadsNumerical: CPU scheduling FCFS Round Robin

User Thread vs Kernel Thread

FeatureUser ThreadKernel Thread
ManagementManaged by a user-level thread libraryManaged directly by the OS kernel
Kernel awarenessKernel is unaware of themKernel is aware and schedules them
Context switchFast, no kernel mode switchSlower, requires kernel mode switch
BlockingOne blocking thread blocks whole processOther threads continue running
PortabilityPortable, runs on any OSOS dependent
ExamplePOSIX Pthreads (user), Java green threadsWindows threads, Linux kernel threads

Given Data

ProcessBurstArrival
A92
B111
C10
D23
E74

Quantum $= 2$.


(a) FCFS

Order by arrival: C(0), B(1), A(2), D(3), E(4).

ProcessArrBurstStartFinishTATWT
C010110
B111112110
A2912211910
D3221232018
E4723302619

$$\text{Avg TAT} = \frac{1+11+19+20+26}{5} = \frac{77}{5} = 15.4$$

$$\text{Avg WT} = \frac{0+0+10+18+19}{5} = \frac{47}{5} = 9.4$$


(b) Round Robin (Quantum = 2)

Enqueue rule: a newly arriving process is added to the ready queue before the just-preempted process is re-added.

Tracing:

  • t=0: only C ready. Run C(1) → t=1, C done.
  • t=1: B arrives, queue [B]. Run B → t=3, B rem 9. During run, A arrives at 2, D arrives at 3. Queue after adding arrivals then B: [A, D, B].
  • t=3: Run A → t=5, A rem 7. E arrives at 4. Queue: [D, B, E, A].
  • t=5: Run D(2) → t=7, D done. Queue: [B, E, A].
  • t=7: Run B → t=9, B rem 7. Queue: [E, A, B].
  • t=9: Run E → t=11, E rem 5. Queue: [A, B, E].
  • t=11: Run A → t=13, A rem 5. Queue: [B, E, A].
  • t=13: Run B → t=15, B rem 5. Queue: [E, A, B].
  • t=15: Run E → t=17, E rem 3. Queue: [A, B, E].
  • t=17: Run A → t=19, A rem 3. Queue: [B, E, A].
  • t=19: Run B → t=21, B rem 3. Queue: [E, A, B].
  • t=21: Run E → t=23, E rem 1. Queue: [A, B, E].
  • t=23: Run A → t=25, A rem 1. Queue: [B, E, A].
  • t=25: Run B → t=27, B rem 1. Queue: [E, A, B].
  • t=27: Run E(1) → t=28, E done. Queue: [A, B].
  • t=28: Run A(1) → t=29, A done. Queue: [B].
  • t=29: Run B(1) → t=30, B done.

Gantt Chart:

C | B | A | D | B | E | A | B | E | A | B | E | A | B | E | A | B
0 1   3   5   7   9  11  13  15  17  19  21  23  25  27 28 29 30

Completion / TAT / WT

ProcessArrBurstFinishTAT = F−AWT = TAT−B
C01110
B111302918
A29292718
D32742
E47282417

$$\text{Avg TAT} = \frac{1+29+27+4+24}{5} = \frac{85}{5} = 17.0$$

$$\text{Avg WT} = \frac{0+18+18+2+17}{5} = \frac{55}{5} = 11.0$$


Summary

MetricFCFSRound Robin (Q=2)
Avg Turnaround Time15.417.0
Avg Waiting Time9.411.0

Watch the Round Robin queue order: using the standard enqueue convention (new arrivals join the ready queue before the preempted process), B finishes at 30 and A at 29, giving Avg TAT = 17.0 and Avg WT = 11.0. A different enqueue order, for example running D at t = 6 to 8, gives finish times B = 29 and A = 27 instead. FCFS is unaffected.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.