OS Assignment1
OS Assignment1
1. Natnael Asnake……………………………….T/0004/12
2. Amanuel Melaku………………………………216/11
3. Hamu Geredo…………………………………..931/11
1
Table of Contents
ABSTRACT ..................................................................................................................................... i
CHAPTER ONE ............................................................................................................................. 1
1. INTRODUCTION ...................................................................................................................... 1
1.1 SCHEDULING ALGORITHMS .......................................................................................... 3
1.1.1Algorithms and Its Characteristics .................................................................................. 3
CHAPTER TWO ............................................................................................................................ 6
2. TEST AND ANALYSIS............................................................................................................. 6
CHAPTER THREE ...................................................................................................................... 16
3. SYSTEM DESIGN SUGGESTION ......................................................................................... 16
CHAPTER FOUR ......................................................................................................................... 17
4. CONCLUSION ......................................................................................................................... 17
REFERENCES ............................................................................................................................. 18
i
Table of Figures
Figure I: Process of Schedulers....................................................................................................... 2
Figure 1: Gantt chart for FCFS ....................................................................................................... 6
Figure 2: Gantt chart for SJF (non-preemptive) ............................................................................. 7
Figure 3: Gantt chart for SJF (preemptive) ..................................................................................... 7
Figure 4: Gantt chart for RR (Q=2) ................................................................................................ 8
Figure 5: Gantt chart for RR (Q=3) ................................................................................................ 8
Figure 6: Gantt chart for RR (Q=4) ................................................................................................ 9
Figure 7: Gantt chart for SRTF (Non-preemptive) ......................................................................... 9
Figure 8: Gantt chart for SRTF (preemptive) ............................................................................... 10
Figure 9: Gantt chart for LRTF (Non-preemptive) ....................................................................... 10
Figure 10: Gantt chart for LRTF (preemptive) ............................................................................. 11
Figure 11: A bar graph showing the comparison of average waiting time for all algorithms. ..... 11
Figure 12: A bar graph showing the average CPU utility for all algorithms. ............................... 12
Figure 13: A bar graph showing the comparison Metrics of Average waiting time For SJF with
Non- preemptive and Preemptive. ................................................................................................ 12
Figure 14: A bar graph showing the comparison Metrics of Average Turnaround time For SJF
with Non-preemptive and Preemptive. ......................................................................................... 13
Figure 15: A bar graph showing the comparison Metrics of Average waiting time For SRTF with
Non-preemptive and Preemptive. ................................................................................................. 13
Figure 16: A bar graph showing the comparison Metrics of Average Turnaround time For SRTF
with Non-preemptive and Preemptive. ......................................................................................... 14
Figure 17: A bar graph showing the comparison Metrics of Average waiting time For LRTF with
Non-preemptive and Preemptive. ................................................................................................. 14
Figure 18: A bar graph showing the comparison Metrics of Average Turnaround time For LRTF
with Non- preemptive and Preemptive. ........................................................................................ 15
Figure 19: A line graph showing the relation of CPU utilization with memory size ................... 16
ii
Table of Table
List of Acronyms
1. Avg…………………………………..Average
2. BT……………………………………Burst Time
3. CPU………………………………….Central Processing unit
4. CT……………………………………Completion Time
5. CT……………………………………Completion Time
6. CT……………………………………Completion Time
7. FCFS………………………………….First Come First Serve
8. LRTF………………………………….Longest Remaining Time First
9. MB…………………………………….Megabyte
10. ms……………………………………...Millisecond
11. PCB……………………………………Printed Circuit Board
12. PID……………………………………Process ID
13. RR…………………………………….Round Robin
14. SRTF………………………………….Shortest Remaining Time First
15. WT…………………………………….Waiting Time
iii
ABSTRACT
Scheduling is a fundamental operating system function, since almost all computer resources are
scheduled before use. The CPU is one of the primary computer resources. Central Processing
Unit (CPU) scheduling plays an important role by switching the CPU among various processes.
CPU scheduling is an area of research where computer engineers used to design efficient
algorithms for scheduling the process in order to get output in the form of optimum turnaround
time and average waiting time. There are many CPU scheduling schemes available. An operating
system can make the computer more productive by allowing processes as many as possible
running at all the time in order to make best use of CPU. The highly efficient CPU scheduler
depends on design of the high-quality scheduling algorithms which suits the scheduling goals. In
this paper, we reviewed various fundamental CPU scheduling algorithms for a single CPU and
shows which algorithm is best for the particular situation.
i
CHAPTER ONE
1. INTRODUCTION
Scheduling is a fundamental operating-system function. Almost all computer resources are
scheduled before use. The CPU is one of the primary computer resources. Thus, its scheduling is
central of operating system design. Thus its scheduling algorithm is heart of the OS design.
When more than one process is runnable, the OS must decide which one is to run first. That part
of the OS concerned with this decision is called scheduler and the algorithm it uses is called
scheduling algorithm. A CPU scheduler is the part of an operating system and responsible for
arbitrating access to the CPU [1]. A scheduler is an OS module that selects the next job to be
admitted into the system and the next process to run. An operating system has three types of
schedulers- long term scheduler (also known as Job scheduler), medium-term scheduler and
short-term scheduler (also known as dispatcher and CPU scheduler).
A) Long-term scheduler
The long-term scheduler (also known as admission scheduler) decides which jobs or processes
are to be admitted to the ready queue (in the Main Memory); that is, when an attempt is made to
execute a program, its admission to the set of currently executing processes is either authorized
or delayed by the long-term scheduler.
Thus, this scheduler dictates what processes are to run on a system, and the degree of
concurrency to be supported at any one time - i.e.: whether a high or low amount of processes are
to be executed concurrently, and how the split between input output intensive and CPU intensive
processes is to be handled. So long term scheduler is responsible for controlling the degree of
multiprogramming. In modern operating systems, this is used to make sure that real time
processes get enough CPU time to finish their tasks
B) Medium-term scheduler
The medium-term scheduler (also known as mid-term scheduler) may decide to swap out a
process which has not been active for some time, or a process which has a low priority, or a
process which is taking up a large amount of memory in order to free up main memory for other
processes, swapping the process back in later when more memory is available, or when the
process has been unblocked and is no longer waiting for a resource.
1
C) Short-term scheduler
The short-term scheduler (also known as CPU scheduler) selects from among the pool of process
resident in memory that are ready to execute, and allocates the CPU to one of them. Thus the
short-term scheduler makes scheduling decisions much more frequent than the long-term or mid-
term schedulers. This scheduler can be preemptive, implying that it is capable of forcibly
removing processes from a CPU when it decides to allocate that CPU to another process, or non-
pre-emptive (also known as "voluntary" or "co-operative"), in that case the scheduler is unable to
force processes off the CPU [1].
2
1.1 SCHEDULING ALGORITHMS
1.1.1Algorithms and Its Characteristics
3
C) Round Robin
The Round Robin (RR) scheduling algorithm assigns a small unit of time, called time slice or
quantum. The ready processes are kept in a queue. The scheduler goes around this queue,
allocating the CPU to each process for a time interval of assigned quantum. New processes are
added to the tail of the queue [4].
Characteristics:
Setting the quantum too short causes too many context switches and lower the CPU
efficiency.
Setting the quantum too long may cause poor response time and approximates FCFS.
Because of high waiting times, deadlines are rarely met in a pure RR system.
RR scheduling involves extensive overhead, especially with a small time unit.
D) Shortest Remaining Time First
Is a scheduling method that is preemptive version of shortest job next scheduling.
Characteristics:
The execution of the process can be stopped after certain amount of time.
At the arrival of every process, the short-term scheduler schedules the process with the
least remaining burst time among the list of available processes and the running process.
Once all the processes are available in the ready queue, no preemption will be done and
the algorithm will work as SJF scheduling.
The context of the process is saved in the PCB.
When the process is removed from the execution and the next process is scheduled.
This PCB is accessed on the next execution of this process.
E) Longest Remaining Time First (LRTF)
It is a preemptive version of Longest Job First (LJF) scheduling algorithm. In this scheduling algorithm, we
find the process with the maximum remaining time and then process it, i.e. check for the maximum
remaining time after some interval of time(say 1 unit each) to check if another process having more
Burst Time arrived up to that time.
Characteristics:
Among all the processes waiting in a waiting queue, CPU is always assigned to the
process having largest burst time.
If two processes have the same burst time then the tie is broken using FCFS.
LJF CPU Scheduling can be of both preemptive and non-preemptive type.
4
F) Highest Response Ratio Next
HRNN is one of the most optimal scheduling algorithms. This is a non-preemptive algorithm in
which, the scheduling is done on the basis of parameter called Response Ratio.
Characteristics:
A Response Ratio is calculated for each of the available jobs and the Job with the highest
response ratio is given priority over the others.
Once a process is selected for execution will run until its completion.
In case, if two processes have same response ratio then the tie is broken using the FCFS
scheduling algorithm.
5
CHAPTER TWO
P1 P2 P3 P4 P5 P6 P7 P8
1 3 5 8 11 15 19 24 29
Figure 1: Gantt chart for FCFS
Table 2: FCFS algorithm table
PID Size(MB) n Priority BT AT CT WT CPU
utility
P1 5 1 1 2 1 3 0 19.5%
P2 3 1 1 2 2 5 1 14.5%
P3 2 1 1 3 3 8 2 5.5%
P4 5 1 1 3 4 11 4 19.5%
P5 4 1 2 4 5 15 6 15.5%
P6 3 1 2 4 6 19 9 14.5%
P7 2 1 2 5 7 24 12 5.5%
P8 2 1 2 5 8 29 16 5.5%
6
B) Shortest Job First (non-preemptive)
P1 P2 P4 P3 P6 P5 P8 P7
1 3 5 8 11 15 19 24 29
1 3 5 8 11 15 19 24 29
7
D). Round Robin (Q=2)
P1 P2 P3 P4 P5 P6 P7 P3 P8 P4 P5 P6 P7 P8 P7 P8
1 3 5 7 9 11 13 15 16 18 19 21 23 25 27 28 29
1 3 5 8 11 14 17 20 23 24 25 27 29
8
F). Round Robin (Q=4)
P1 P2 P3 P4 P5 P6 P7 P8 P7 P8
1 3 5 8 11 15 19 23 27 28 29
Figure 6: Gantt chart for RR (Q=4)
Table 7: RR (Q=4) algorithm table
PID Size(MB) n Priority BT AT CT WT CPU
utility
P1 5 1 1 2 1 3 0 19.5%
P2 3 1 1 2 2 5 1 14.5%
P3 2 1 1 3 3 8 2 5.5%
P4 5 1 1 3 4 11 4 19.5%
P5 4 1 2 4 5 15 6 15.5%
P6 3 1 2 4 6 19 9 14.5%
P7 2 1 2 5 7 28 16 5.5%
P8 2 1 2 5 8 29 16 5.5%
Average waiting time: 6.75 Average CPU utility: 12.5%
Average Turnaround time: 10.25
G) Shortest Remaining Time First (non-preemptive)
P1 P2 P3 P4 P5 P6 P7 P8
1 3 5 8 11 15 19 24 29
Figure 7: Gantt chart for SRTF (Non-preemptive)
Table 8: SRTF (Non-preemptive) algorithm table
PID Size(MB) n Priority BT AT CT WT CPU
utility
P1 5 1 1 2 1 3 0 19.5%
P2 3 1 1 2 2 5 1 14.5%
P3 2 1 1 3 3 8 2 5.5%
P4 5 1 1 3 4 11 4 19.5%
P5 4 1 2 4 5 15 6 15.5%
P6 3 1 2 4 6 19 9 14.5%
P7 2 1 2 5 7 24 12 5.5%
P8 2 1 2 5 8 29 16 5.5%
9
H) Shortest Remaining Time First (preemptive)
P1 P1 P2 P2 P3 P3 P3 P4 P5 P6 P7 P8
1 2 3 4 5 6 7 8 11 15 19 24 29
Figure 8: Gantt chart for SRTF (preemptive)
Table 9: SRTF (preemptive) algorithm table
PID Size(MB) n Priority BT AT CT WT CPU
utility
P1 5 1 1 2 1 3 0 19.5%
P2 3 1 1 2 2 5 1 14.5%
P3 2 1 1 3 3 8 2 5.5%
P4 5 1 1 3 4 11 4 19.5%
P5 4 1 2 4 5 15 6 15.5%
P6 3 1 2 4 6 19 9 14.5%
P7 2 1 2 5 7 24 12 5.5%
P8 2 1 2 5 8 29 16 5.5%
1 3 6 11 16 20 24 27 29
Figure 9: Gantt chart for LRTF (Non-preemptive)
Table 10: LRTF (Non-preemptive) algorithm table
PID Size(MB) n Priority BT AT CT WT CPU
utility
P1 5 1 1 2 1 3 0 19.5%
P2 3 1 1 2 2 29 25 14.5%
P3 2 1 1 3 3 6 0 5.5%
P4 5 1 1 3 4 27 20 19.5%
P5 4 1 2 4 5 20 11 15.5%
P6 3 1 2 4 6 24 14 14.5%
P7 2 1 2 5 7 11 1 5.5%
P8 2 1 2 5 8 16 3 5.5%
10
J) Longest Remaining Time First (preemptive)
P1 P2 P3 P4 P5 P6 P7 P8 P7 P8 P5 P6 P7 P8 P3 P4 P5 P6 P7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
P8 P1 P2 P3 P4 P5 P6 P7 P8
20 21 22 23 24 25 26 27 28 29
Figure 10: Gantt chart for LRTF (preemptive)
Table 11: LRTF (preemptive) algorithm table
PID Size(MB) n Priority BT AT CT WT CPU
utility
P1 5 1 1 2 1 22 19 19.5%
P2 3 1 1 2 2 23 19 14.5%
P3 2 1 1 3 3 24 18 5.5%
P4 5 1 1 3 4 25 18 19.5%
P5 4 1 2 4 5 26 17 15.5%
P6 3 1 2 4 6 27 17 14.5%
P7 2 1 2 5 7 28 16 5.5%
P8 2 1 2 5 8 29 16 5.5%
Average waiting time: 17.5 Average CPU utility: 12.5%
Average Turnaround time: 21
15 RR(Q=3)
RR(Q=4)
10
SRTF(Non-Preemptive)
5 SRTF(Preemptive)
LRTF(Non-Preemptive)
0 LRTF(Preemptive)
P1 P2 P3 P4 P5 P6 P7 P8 AvgWT
Process ID
Figure 11: A bar graph showing the comparison of average waiting time for all
algorithms.
11
b) Bar graph which indicates the avaerage CPU utility:
Time(ms)
0.25
FCFS
0.2
SJF(Non-Preemptive)
SJF(Preemptive)
0.15
RR(Q=2)
RR(Q=3)
0.1
RR(Q=4)
0.05 SRTF(Non-preemptive)
SRTF(Preemptive)
0 LRTF(Non-Preemptive)
P1 P2 P3 P4 P5 P6 P7 P8 Avg LRTF(Preemptive)
CPU
utility
Process ID
Figure 12: A bar graph showing the average CPU utility for all algorithms.
Time(ms)
18
16
14
12
10
SJF(Non-Preemptive)
8
SJF(Preemptive)
6
0
P1 P2 P3 P4 P5 P6 P7 P8 AVG
WT
Process ID
Figure 13: A bar graph showing the comparison Metrics of Average waiting time For
SJF with Non- preemptive and Preemptive.
12
Time(ms)
25
20
15
SJF(Non-preemptive)
10 SJF(Preemptive)
0
P1 P2 P3 P4 P5 P6 P7 P8 Avg TAT
Process ID
Figure 14: A bar graph showing the comparison Metrics of Average Turnaround time
For SJF with Non-preemptive and Preemptive.
Time(ms)
18
16
14
12
10
SRTF(Non-Preemptive)
8
SRTF(Preemptive)
6
0
P1 P2 P3 P4 P5 P6 P7 P8 Avg WT
Process ID
Figure 15: A bar graph showing the comparison Metrics of Average waiting time For
SRTF with Non-preemptive and Preemptive.
13
Time(ms)
25
20
15
SRTF(Non-Preemptive)
10 SRTF(Preemptive)
0
P1 P2 P3 P4 P5 P6 P7 P8 Avg TAT
Process ID
Figure 16: A bar graph showing the comparison Metrics of Average Turnaround time
For SRTF with Non-preemptive and Preemptive.
Time(ms)
30
25
20
15 LRTF(Non-Preemptive)
LRTF(Preemptive)
10
0
P1 P2 P3 P4 P5 P6 P7 P8 Avg WT
Process ID
Figure 17: A bar graph showing the comparison Metrics of Average waiting time For
LRTF with Non-preemptive and Preemptive.
14
Time(ms)
30
25
20
15 LRTF(Non-Preemptive)
LRTF(Preemptive)
10
0
P1 P2 P3 P4 P5 P6 P7 P8 Avg TAT
Process ID
Figure 18: A bar graph showing the comparison Metrics of Average Turnaround time
For LRTF with Non- preemptive and Preemptive.
15
CHAPTER THREE
90%
80%
70%
60%
50% Size
CPU utility
40%
30%
20%
10%
0%
20 50 58 75
RAM size(MB)
Figure 19: A line graph showing the relation of CPU utilization with memory size
16
CHAPTER FOUR
4. CONCLUSION
The calculation of three algorithms shows the different average waiting time. The FCFS is better
for a small burst time. The SJF is better if the process comes to processor simultaneously. The
last algorithm, Round Robin, is better to adjust the average waiting time desired. Round Robin
quantum time will set it towards more SJF or FCFS value. All algorithms are good, but the speed
of the process depends on the processor load. The relationship between CPU utilization and
memory size is a process can occupy all CPUs of a system but use only a minimal amount of
memory. Also, a process can allocate all memory available on a system but only use minimal
CPU time.
17
REFERENCES
[1]. H. Heidari dan A. Chalechale, “Scheduling in Multiprocessor System Using Genetic
Algorithm,” International Journal of Advanced Science and Technology, vol. 43, pp. 81-94,
2012.
[2]. C. Bajaj, A. Dogra dan G. Singh, “Review And Analysis Of Task Scheduling Algorithms,”
International Research Journal of Engineering and Technology, vol. 2, no. 3, pp. 1449-1452,
2015.
[3]. A. Noon, A. Kalakech dan S. Kadry, “A New Round Robin Based Scheduling Algorithm for
Operating Systems: Dynamic Quantum Using the Mean Average,” IJCSI International Journal of
Computer Science Issues, vol. 8, no. 3, pp. 224-229, 2011.
[4]. I. S. Rajput dan D. Gupta, “A Priority based Round Robin CPU Scheduling Algorithm for
Real Time Systems,” International Journal of Innovations in Engineering and Technology, vol. 1,
no. 3, pp. 1-11, 2012.
[5]. Arpaci-Dusseau, “Shortest Job Next,” [Online]. Available:
https://en.wikipedia.org/wiki/Shortest_job_next. [Diakses 1 May 2016.
[6]. Md. Mamunur Rashid and Md. Nasim Adhtar; “A New Multilevel CPU Scheduling
Algorithm”, Journals of Applied Sciences 6 (9): 2036-2039, 2009.
18