Assignment 3 - Ps

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

UNIVERSITI MALAYSIA TERENGGANU

CSF3213 OPERATING SYSTEM (K2)

BANCHELOR OF COMPUTER SCIENCE (MOBILE COMPUTING)


WITH HONORS

PROCESS SCHEDULING
SEMESTER 2 2023/2024

PREPARED FOR:
DR. ABDUL AZIZ K ABDUL HAMID
PREPARED BY:
AMAL HAZIRAH BINTI SAIFUDDIN (S67202)
1. Explain the difference between preemptive and nonpreemptive scheduling.

Preemptive scheduling: The Operating System can interrupt a running process or thread
and allocate the CPU to another process. This interruption based on priorities, time
slices or other criteria. The operating system has control over the CPU and can prempt
a process even if it still actively using the CPU. This allows for better responsiveness
and fairness among processes but may incur some overhead due to frequent context
switches.

Nonpreemptive scheduling: Once a process or thread starts executing on the CPU, it


will continue to run until it voluntarily relinquishes the CPU, such as when it completes
its execution or blocks for I/O operations. The operating system does not forcibly
interrupt the process to allocate the CPU to other process. Nonpreemptive scheduling
provides simplicity in terms of context switching but can result in lower responsiveness
if a long-running process hogs the CPU, causing delays for other processes.

2. Suppose that the following processes arrive for execution at the times indicated. Each
process will run for the amount of time listed. In answering the questions, use
nonpreemptive scheduling, and base all decisions on the information you have at the time
the decision must be made.

Process Arrival Time Burst Time


P1 0.0 8
P2 0.4 4
P3 1.0 1

a. What is the average turnaround time for these processes with the FCFS scheduling
algorithm?

Completion time:
P1:8
P2:12
P3:13

Average turnaround time = (8+12+13)/3 = 11 units

b. What is the average turnaround time for these processes with the SJF scheduling
algorithm?

Completion time:
P1:8
P2:8+4 = 12
P3:12+1=13

Average turnaround time =(8+12+13)/3 = 11 units


c. The SJF algorithm is supposed to improve performance, but notice that we chose to run
process P1 at time 0 because we did not know that two shorter processes would arrive
soon. Compute what the average turnaround time will be if the CPU is left idle for the
first 1 unit and then SJF scheduling is used. Remember that processes P1 and P2 are
waiting during this idle time, so their waiting time may increase. This algorithm could
be called future-knowledge scheduling.

Completion time:
P1:1+8 = 9
P2: 1 +4 = 5
P3: 5+1 = 6

Average turnaround time = (9+5+6) = 6.67 units

You might also like