Simulation Of Scheduling Algorithms
✅ Paper Type: Free Essay | ✅ Subject: Computer Science |
✅ Wordcount: 3559 words | ✅ Published: 3rd May 2017 |
Abstract- In this term paper we have discuss simulation of scheduling algorithm. We have discuss various type of scheduling algorithm such as robin round, first comes first served, shortest job first, and etc. We also discuss its advantages and disadvantages. In this term paper we take some c programme based on this scheduling algorithm to understand properly. We also include some graphical representatiion of each scheduling. From which we can differentiate between each algorithm.
Keywords- In this term paper we use some keyword Round Robin(RR), First Come First Serve (FCFS), Shortest Job First(SJF), Process Control Block (PCB), Shortest Time Remaining (SRT).
INTRODUCTION
Scheduling is a fundamental operating-system function. Whenever the CPU becomes idle, the operating system must select one of the processes in the ready queue to be executed. The selection process is carried out by the short-term scheduler. The scheduler selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them.
All processes in the ready queue are lined up waiting for a chance to run on the CPU. The records are generally the PCBs (Process Control Block) of the processes.
Another important component involved in the CPU
scheduling function is the dispatcher. The dispatcher is the module that gives control of the CPU to the
processes selected by the short-term scheduler. This function involves:
• Switching context
• Jumping to the proper location in the user program to restart that program.
Our goal is to simulate the process scheduling algorithms to get a more accurate evaluation on how choice of a particular scheduling algorithm can effect CPU utilization and how a scheduler decides when processors should be assigned, and to which processes. Different CPU scheduling algorithms have different properties and may favour one class of processes over another.
We have programmed a model of the computer system and implemented scheduling algorithms using Software data structures which represent the major components of the system which we have discussed in this section.
2. PROPOSAL
When system has a choice of processes to execute, it must have a strategy -called a Process Scheduling Policy-for deciding which process to run at a given time .A scheduling policy should attempt to satisfy certain performance criteria, such as maximizing:
• Throughput
• Latency
• Preventing Indefinite postponement of Process
• Maximizing Process Utilization
It is the job of the scheduler or dispatcher to assign a processor to the selected process. In our project various Process Scheduling Algorithms that determine at runtime which process runs next .These algorithms decide when and for how long each process runs; they make choices about
• Preemptibility
• Priorities
• Running time
• Time-to-Completion
• Fairness
We will be simulating these Scheduling Algorithms and comparing them against various parameters mentioned above.
BACKGROUND
What is Process :-A process is the locus of control of a procedure in execution that is manifested by the existence of a data structure called Process Control Block.
Each process has its own address space, which typically consists of Text region, Data region and Stack region. The Text region stores the code that the processor executes.
The Data region stores the variables and dynamically allocated memory that the process uses during execution. The Stack region stores instructions and local variables for active procedure calls. The contents of the Stack grow as the process issues nested procedure calls and shrink as procedures return.
4.WHAT IS PROCESSOR SCHEDULING?
-When a system as a choice of processes to execute, it must have a strategy for deciding which process to run at a given time. This strategy is known as Processor Scheduling Policy. Different process scheduling algorithms have different properties and may favor one class of processes over another. In choosing which algorithm to use in a particular situation, we compare the following characteristics to compare the algorithms.
CPU Utilization -We want to keep the CPU as busy as possible. It ranges from 0 to 100%. In real systems
it ranges from 40% to 90%. For the purpose of this simulation we have assumed that CPU utilization is 100%.
Throughput -The work done by the CPU is directly proportional to the CPU utilization. The number of processes completed per unit time, called throughput, is the measure of work done by the CPU. Algorithms should try to maximize the throughput.
Turnaround time- The time interval from submission of job to the completion of job is termed as the turnaround time. It includes waiting time of the process and the service time of the process.
Waiting time -The amount of time process spent waiting in the ready queue is termed as Waiting time. Any algorithm does not affect the service time of the process but does affect the waiting time of the process. Waiting time should be kept to the minimum.
Get Help With Your Essay
If you need assistance with writing your essay, our professional essay writing service is here to help!
Find out more about our Essay Writing Service
Response time – The time interval from the submission of the process to the ready queue until the process receives the first response is known as Response time. Response time should always be kept minimum. Besides the above features, a scheduling algorithm must also have the following properties:
• Fairness
• Predictability
• Scalability
5. SIMULATION- In our simulation the ready queue has been programmed to serve the processes in the First in First out, Round Robin, Shortest Process first, Highest Response Ration Next and also Shortest Remaining time.
The simulator has a variable representing a clock; as this variables value is increased, the simulator modifies the system state to reflect the activities of the devices, the processes, and the scheduler. Our system has a function called Process Ready which checks which processes are ready to enter the system depending on the current clock. Preemption is performed based on the current clock.
If the next process in the ready queue should get the CPU the current process is pushed into the queue and the next process, based on how the priority of the processes is calculated in ready queue, is taken and given the CPU time. We call this in real systems as context switch .We will be providing this overhead a simple variable which we fill add to a process when it is preempted.
The scheduler is an abstract class in which we have defined the basic components which are needed by the scheduler like ready queue .FIFO, RR, SPF, SRT and HRRN are the classes which extend this scheduler class and implement the ready queue based on specific scheduler.
The data that we are using to drive the simulation is generated using a random-number generator. The generator is programmed to generate processes, CPU-burst times, Arrivals and Finish time.
The process PCB in our simulation consists of following attributes:
Process Id
Process ServiceTime
Process ArrivalTime
Process FinishTime
Process ResponseTime
The same set of processes is feed into the scheduling algorithm to evaluate the algorithms effect on the processes and CPU. These are initialized for all the processes that we randomly generate .Once the process gets the CPU its service time gets updated and if the simulation performs a context switch which preempts the current running process and puts it at
the back of the ready queue i.e. we save the PCB of the process. After this the first process in the ready queue is given the block .In the end the system outputs the Arrival Time, Service Time, Turn around Time, Waiting Time and Response Time for each process executed by the system. The output formats, the input and the Analysis using this simulation model are shown in the sections that follow:
A simple Class Diagrame :-
6. SCHEDULING ALGORITHM
A scheduling algorithm is the method by which threads, processes or data flows are given access to system resources (e.g. processor time, communications bandwidth). This is usually done to load balance a system effectively or achieve a target quality of service. The need for a scheduling algorithm arises from the requirement for most modern systems to perform multitasking (execute more than one process at a time) and multiplexing (transmit multiple flows simultaneously)
Type of Scheduling algorithm
Scheduling algorithm :-
First Come First Serve (FCFS)
Round Robin
Shortest Job First
Shortest Remaining Time
Highest Response Ratio Next (HRRN)
Fixed priority pre-emptive scheduling
FIRST COME FIRST SERVE (FCFS) :-
CPU scheduling deals with the problem of deciding which of the processes in the ready queue is to be allocated the CPU. There are many different CPU scheduling algorithms. By far the simplest CPU-scheduling algorithm is the first-come, first-served (FCFS) scheduling algorithm. With this scheme, the process that requests the CPU first is allocated the CPU first. The implementation of the FCFS policy is easily managed with a FIFO queue. When a process enters the ready queue, its PCB is linked onto the tail of the queue. When the CPU is free, it is allocated to the process at the head of the queue. The running process is then removed from the queue. The code for FCFS scheduling is simple to write and understand. The average waiting time under the FCFS policy, however, is often quite long.
C- programming for this scheduling algorithm is given below. I only present the main part of the programme.
/* Programme for FCFS*/
#include #include using namespace std;
int cont, ctr;
class FCFS{ //Class used for the simulation
public: //public elements of the class
void input();
void gantt();
protected: //protected elements of the class
float wt, bt, arr, bt2;
float awt;
int main(){ //main function
FCFS IT2B;
cout<<"Input number of jobs.n";
cin>>ctr;
if(ctr>=3&&ctr<=6){
system(“cls”);
IT2B.input(); //invocation
}else{
cout<<"INVALID ENTRY!!n";
cout<<"Min is 3nMax is 6n Press any key to re-input.n";
cin>>cont;
system(“cls”);
main();
return 0;
void FCFS::input() //input() function of class FCFS
wt=0;
bt2=0;
cout<<"JOBStBTn";
for(arr=1;arr<=ctr;arr++){
cout<<"Job"< bt2=bt+bt2;
wt=bt2+wt;
awt=(wt-bt2)/ctr;
cout<<"AVERAGE WAITING TIME IS: "< cin>>cont;
/*void FCFS::gantt()
Limitations: – In FCFS, average waiting time is quite longer. If we have a processor bound job (generally with longer service time) and other I/O bound jobs. And if, processor bound job is allocated the processor time, then it will hold the CPU. As a result, other I/O bound jobs will keep waiting in the ready queue and the I/O devices will remain idle.
Like in the test cases we observed, process P3 despite having a very short service time had to wait for long till all the processes ahead of it ran to completion.
Average Turn around Time: 12
Average Waiting Time: 7.2
Average Response Time: 7.2
6.2. ROUND ROBIN
The round-robin (RR) scheduling algorithm is designed especially for time-sharing systems. It is similar to FCFS scheduling, but preemption is added to switch between processes. A small unit of time, called a time quantum or time slice, is defined. A time quantum is generally from 10 to 100 milliseconds. The ready queue is treated as a circular queue. The CPU scheduler goes around the ready queue, allocating the CPU to each process for a time interval of up to l time quantum. To implement RR scheduling, we keep the ready queue as a FIFO queue of processes. New processes are added to the tail of the ready queue. The CPU scheduler picks the first process from the ready queue, sets a timer to interrupt after l time quantum, and dispatches the process .
C- programming for this scheduling algorithm is given below. I only present the main part of the programme.
};
}
}
{
}
}
{
*/
/* Programme for ROUND ROBIN*/
Cite This Work
To export a reference to this article please select a referencing stye below:
Related Services
View allDMCA / Removal Request
If you are the original writer of this essay and no longer wish to have your work published on UKEssays.com then please: