Saint Mary’s University
Bayombong, Nueva Vizcaya 3700
School of Engineering, Architecture and Information Technology
Operat
ing
Syste
m and
Applic
ations
Labora
Prepared by:
tory
Bermelita T. Domingo
Faculty
Manua
l
Table of Contents
No. List of Experiments Page No.
1 Process Scheduling: FCFS Simulation
2 Process Scheduling: SJF Simulation
3 Process Scheduling: Priority Simulation
4 Process Scheduling: Round-Robin Simulation
5 Process Synchronization Simulation
6 Deadlock Avoidance: Banker’s Algorithm
Simulation
Exercise No.: 1
Title of Exercise: Process Scheduling: First-come First-serve (FCFS)
Simulation
Objective: Using FCFS algorithm, find the average waiting time during
process execution.
Software Requirements: Eclipse/ Visual Studio.Net
Theory
CPU can only run a single process at a time. Multiple processes all
queued and wanting CPU time
Scheduling answers the question: Which process to run at a given point
in time?
Processes undergo a CPU – I/O burst cycle
CPU cycle – process doing computations
I/O burst – process waiting for I/O
This loop goes over and over during the course of program execution
Gantt chart
First-come First-served Algorithm
Processes are executed in the order that they arrive in the ready
queue.
For example, consider process P1 to P4 with burst times 5, 3, 4
and 6 arriving in that order at time 0. The Gantt chart would be
FCFS is a very simple scheduling algorithm to implement. However,
the first come first served nature does have some problems
Consider P1 burst time 100, P2 to P5 with burst time of 1
If process execution is done P1, P2, P3, P4, P5 then
Wait time: (0 + 100 + 101 + 102 + 103) / 5 = 81.2 seconds
If process execution is done P2, P3, P4, P5, P1 then:
Wait time: (0 + 1 + 2 + 3 + 4) / 5 = 2 seconds
As can be seen, sometimes having short processes execute first
lessens the average wait time.
Also, if P1 appears again and again in the queue, then process
execution would be delayed again and again, decreasing
throughput.
Procedure
Example:
Process Burst Time
P1 24
P2 3
P3 3
Suppose that the processes arrive in the order: P1, P2, P3
The Gantt chart for the schedule is:
Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting time: (0 + 24 + 27)/3 = 17
Algorithm
1. Start
2. Declare the array size
3. Read the number of processes to be inserted
4. Read the Burst times of processes
5. Calculate the waiting time of each process
wt[i+1]=bt[i]+wt[i]
6. Calculate the turnaround time of each process
tt[i+1]=tt[i]+bt[i+1]
7. Calculate the average waiting time and average turnaround time.
8. Display the values
9. Stop
Sample Program Output
INPUT
Enter no of processes:
3
Enter burst time:
12
8
20
EXPECTED OUTPUT
bt wt tt
12 0 12
8 12 20
20 20 40
aw=10.666670
at=24.00000
QUESTIONS:
1. What is First-Come-First-Served (FCFS) Scheduling?
2. Why CPU scheduling is required?
3. CPU performance is measured through ________.
a) Throughput b) MHz c) Flaps d) None of the above
4. Which of the following is a criterion to evaluate a scheduling
algorithm?
A. CPU Utilization: Keep CPU utilization as high as possible.
B. Throughput: number of processes completed per unit time.
C. Waiting Time: Amount of time spent ready to run but not running.
D. All of the above
Exercise No.: 2
Title of Exercise: Process Scheduling: Shortest-Job-First (SJF)
Simulation
Objective: Using SJF algorithm, find the average waiting time during
process execution.
Software Requirements: Eclipse/ Visual Studio.Net
Theory
Exercise No.: 3
Title of Exercise: Process Scheduling: Priority Simulation
Objective: Using Priority algorithm, find the average waiting time
during process execution.
Software Requirements: Eclipse/ Visual Studio.Net
Theory
Exercise No.: 4
Title of Exercise: Process Scheduling: Round-Robin Simulation
Objective: Using Round-Robin algorithm, perform a simulation of
process execution.
Software Requirements: Eclipse/ Visual Studio.Net
Theory