0% found this document useful (0 votes)
20 views5 pages

OSSP Lab Test-1 - Wed 10 To 12 Noon

Uploaded by

23103400
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)
20 views5 pages

OSSP Lab Test-1 - Wed 10 To 12 Noon

Uploaded by

23103400
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

OSSP Lab Test-1

Wed 10 to 12 noon

Set-A
Question 1 – Multi-Threaded Priority + Aging Boost Scheduler (20 Marks)

Write a Linux C program using POSIX threads (pthreads) to simulate a Priority + Aging Boost -based CPU
scheduler where:

1. Input:

o Number of processes n.

o For each process: a name (string), burst time, and priority (Priority + Aging Boost (PAB)). Where
Schedule higher-priority(with higher number) processes first, but automatically raise the
priority of any waiting process over time(more than 5 ms) so nothing starves.

2. Threads:

o Main thread: Reads all process information and creates two worker threads:

▪ Thread A sorts the processes by priority (highest first) and stores the schedule order.

▪ Thread B computes waiting time and turnaround time for each process using the sorted
list.

3. Synchronization:

o Use a pthread mutex + condition variable so that Thread B waits until Thread A finishes sorting.

4. Output:

o Display a Gantt chart of execution order.

o Print each process’s Name, Burst Time, Priority, Waiting Time, and Turnaround Time.

o Print the Average Waiting Time and Average Turnaround Time.

Expected output: === Priority + Aging Boost Scheduler ===

=== Priority + Aging Boost Scheduler ===

Main Thread: reading 3 processes...

Process List:

P1 Burst=10 BasePriority=3

P2 Burst=20 BasePriority=1
P3 Burst=5 BasePriority=1

Main Thread: creating Thread A to sort by effective priority

Thread A: applying PAB (boost +1 every 5 ms of wait) ...

Thread A: final schedule order -> [P1, P3, P2]

Thread A: signaling Thread B

Thread B: computing waiting and turnaround times...

---------------------------------------------------------------------

Process | Burst | BasePri | FinalOrder | Waiting(ms) | Turnaround(ms)

---------------------------------------------------------------------

P1 | 10 | 3 | 1 | 0 | 10

P3 | 5 | 1 | 2 | 10 | 15

P2 | 20 | 1 | 3 | 15 | 35

---------------------------------------------------------------------

Average Waiting Time = (0 + 10 + 15) / 3 = 8.33 ms

Average Turnaround Time = (10 + 15 + 35) / 3 = 20.0 ms

---------------------------------------------------------------------

Main Thread: Completed. Exiting.

Marking Scheme (for each question)

Component Marks

Correct use of pthreads (create/join) 4

Proper synchronization (mutex/cond vars) 4

Accurate scheduling logic 6

Correct calculations & formatted output 4

viva 2

Total 20
SET-B
Question 2 – Dynamic Quantum Round Robin (DQRR) with Threaded Clock Tick (20 Marks)

Traditional RR uses one fixed time-quantum for all processes.


DQRR keeps the RR queue but adapts each process’s time-quantum based on its recent CPU usage:

• If a process finishes before using its full slice → next slice stays the same.

• If a process repeatedly uses the full slice without blocking → next slice is shortened (to give others
more turns).

• If a process often blocks early for I/O → next slice is lengthened slightly (less context-switch
overhead).

Problem Statement

Create a Linux C multithreaded program to simulate a Dynamic Quantum Round Robin (DQRR) Sceduling
algorithm with a time quantum of 2 ms, as follows:

1. Input:

o Number of processes n.

o For each process: Process ID and Burst Time.

2. Threads:

o Clock Thread: Generates a “CPU tick” every 1 ms (use usleep()).

o Scheduler Thread: Implements Dynamic Quantum Round Robin (DQRR) scheduling, consuming
CPU ticks and updating remaining burst times.

o Logger Thread: Periodically (every 5 ms) prints the current process running and the remaining
burst times of all processes.

3. Synchronization:

o Protect the ready queue and shared data using a pthread mutex.

o Use a pthread condition variable to signal the scheduler when a clock tick occurs.

4. Output:

o Final Gantt Chart showing the order and slice of execution.

o Total completion time and CPU utilization (assume no idle time).

o Waiting time and turnaround time for each process.

Here’s a simple sample output you can show when running the described program.
Assume:

• Time quantum (initial) = 2 ms


• Processes entered

Process Burst Time

P1 5 ms

P2 7 ms

P3 4 ms

Program Output (example)

Enter number of processes: 3

Enter PID and Burst Time:

P1 5

P2 7

P3 4

[Logger] t=0 ms : Running P1 | Remaining: P1=5 P2=7 P3=4

[Logger] t=5 ms : Running P3 | Remaining: P1=3 P2=5 P3=4

[Logger] t=10 ms: Running P2 | Remaining: P1=1 P2=5 P3=2

[Logger] t=15 ms: Running P2 | Remaining: P1=0 P2=1 P3=0

All processes completed.

(Logger prints every 5 ms, so you see only a few snapshots even though the clock ticked every 1 ms.)

Final Gantt Chart

Order and slice of execution produced by the scheduler:

0–2 : P1

2–4 : P2

4–6 : P3

6–8 : P1

8–10 : P2

10–12: P3

12–14: P2
14–15: P2

Calculated Metrics

Process Burst Waiting Time Turnaround Time

P1 5 ms 6 ms 11 ms

P2 7 ms 8 ms 15 ms

P3 4 ms 7 ms 11 ms

• Total completion time: 15 ms

• CPU utilization: 100 % (no idle gaps)

Explanation

• Clock Thread ticked every 1 ms.

• Scheduler Thread gave each ready process up to its dynamic quantum (starting at 2 ms).

o If a process finished before its slice, its quantum could grow slightly next time.

o If it always used the full slice, quantum stayed at 2 ms.

• Logger Thread woke every 5 ms to print the running process and remaining bursts.

This simple run shows how the Dynamic Quantum Round Robin keeps CPU busy and adapts slice lengths
a little while maintaining fairness like standard RR.

Marking Scheme (for each question)

Component Marks

Correct use of pthreads (create/join) 4

Proper synchronization (mutex/cond vars) 4

Accurate scheduling logic 6

Correct calculations & formatted output 4

viva 2

Total 20

You might also like