.

Monday, April 1, 2019

Simulation Of Scheduling Algorithms

Simulation Of Scheduling AlgorithmsAbstract- In this end pointination piece we have discuss fashion model of programming algorithmic ruleic programic programic program. We have discuss divers(a) type of schedule algorithm such as robin round, outset develops setoff served, shortest job first, and etc. We as well discuss its advantages and disadvantages. In this term paper we take some c programmeme based on this schedule algorithm to understand properly. We also involve some vivid representatiion of separately programming. From which we can differentiate between each algorithm.Keywords- In this term paper we use some keyword Round Robin(RR), offshoot commence offset Serve (FCFS), Shortest Job First(SJF), growth visit Block (PCB), Shortest epoch remain (SRT).INTRODUCTIONScheduling is a fundamental operating- ashes social occasion. Whenever the do byor becomes idle, the operating organization must select one of the operationes in the coiffe come up to be executed. The selection butt against is carried out by the short-term scheduler. The scheduler selects from among the swear outes in reminiscence that ar groom to execute, and allocates the mainframe to one of them. tout ensemble cultivatees in the machinate queue be lined up hold for a put on the line to provide on the mainframe computer. The records are broadly speaking the PCBs ( exhibit Control Block) of the subroutinees.Another of the essence(predicate) component involved in the CPUscheduling function is the appetizer. The crank is the module that gives control of the CPU to the motiones selected by the short-term scheduler. This function involves fault linguistic circumstance Jumping to the proper location in the user program to restart that program.Our goal is to simulate the fulfill scheduling algorithms to get a to a greater extent accurate evaluation on how choice of a situation scheduling algorithm can effect CPU utilization and how a scheduler deci des when mainframe computers should be assigned, and to which workes. Different CPU scheduling algorithms have different properties and may favour one cast of processes over another.We have programmed a sit around of the computer placement and imposeed scheduling algorithms employ Software information structures which represent the major components of the arrangement which we have discussed in this section.2. PROPOSALWhen system has a choice of processes to execute, it must have a strategy -called a sue Scheduling Policy-for deciding which process to run at a apt(p) sequence .A scheduling constitution should attempt to satisfy accepted performance criteria, such as maximizing Throughput Latency Preventing Indefinite cargo hairgrip of Process Maximizing Process UtilizationIt 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 runmagazine which process runs nig h .These algorithms decide when and for how commodious each process runs they make choices about Preemptibility Priorities Running snip age-to-Completion justiceWe forget be simulating these Scheduling Algorithms and comparing them against various parameters mentioned above.BACKGROUNDWhat is Process -A process is the locus of control of a procedure in movement 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, information region and Stack region. The Text region stores the code that the processor executes.The selective information region stores the variables and dynamically allocated memory that the process uses during execution. The Stack region stores book of 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?-Wh en a system as a choice of processes to execute, it must have a strategy for deciding which process to run at a given snip. This strategy is known as central processor Scheduling Policy. Different process scheduling algorithms have different properties and may favor one phase of processes over another. In choosing which algorithm to use in a extra situation, we compare the following characteristics to compare the algorithms.CPU Utilization -We want to assert the CPU as busy as possible. It ranges from 0 to 100%. In real systemsit ranges from 40% to 90%. For the purpose of this simulation we have delusive 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 whole eon, called throughput, is the heartbeat of work done by the CPU. Algorithms should try to maximize the throughput.Turnaround cadence- The beat interval from submission of job to the completion of job is termed as th e reverse gear clip. It includes wait metre of the process and the usefulness time of the process. hold time -The amount of time process spent waiting in the pass water queue is termed as Waiting time. Any algorithm does not restore the usefulness time of the process but does affect the waiting time of the process. Waiting time should be kept to the minimum.Response time The time interval from the submission of the process to the prepare queue until the process receives the first resolution is known as Response time. Response time should continuously be kept minimum. Besides the above features, a scheduling algorithm must also have the following properties Fairness Predictability Scalability5. SIMULATION- In our simulation the active 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 be time.The simulator has a variable representing a clock as this variables va lue 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 rig which checks which processes are ready to enter the system depending on the current clock. pre-emption 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 anteriority of the processes is calculated in ready queue, is interpreted and given the CPU time. We call this in real systems as context switch .We get out be providing this overhead a unanalyzable 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 equivalent ready queue .FIFO, RR, SPF, SRT and HRRN are the classes which extend this scheduler class and implement the ready queue based on specific sc heduler.The data that we are apply to drive the simulation is fall ind employ a random-number generator. The generator is programmed to generate processes, CPU-burst times, Arrivals and goal time.The process PCB in our simulation consists of following attributesProcess IdProcess wait on cartridge holderProcess ArrivalTimeProcess FinishTimeProcess ResponseTimeThe like 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 inspection and repair time gets updated and if the simulation performs a context switch which preempts the current running process and puts it atthe 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, dish out 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 followA simple Class Diagrame -6. SCHEDULING ALGORITHMA 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 tonicity of service. The need for a scheduling algorithm arises from the requirement for most forward-looking systems to perform multi lineing (execute more than one process at a time) and nine-foldxing (transmit multiple flows simultaneously)Type of Scheduling algorithmScheduling algorithm -First Come First Serve (FCFS)Round RobinShortest Job FirstShortest rest TimeHighest Response Ratio Next (HRRN)Fixed precession pre-emptive schedulingFIRST COME FIRST SERVE (FCFS) -CPU scheduling deals with the business of deciding which of the processes in the r eady 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 tie in 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 add up waiting time under the FCFS policy, however, is often quite colossal.C- programming for this scheduling algorithm is given below. I notwithstanding present the main array of the programme./* Programme for FCFS*/includeinclude //Library for clearing the screenusing namespace stdint cont, ctrclass FCFS //Class used for the simulation public // public elements of the class void input() void gantt() protected //protected elements of the class botch wt, bt, arr, bt2 float awtint main() //main function FCFS IT2B cout cinctr if(ctr=3ctr system(cls)IT2B.input() //invocation else cout cout cincont system(cls) main() return 0 void FCFSinput() //input() function of class FCFS wt=0 bt2=0 cout for(arr=1arr coutbt cout bt2=bt+bt2 wt=bt2+wtawt=(wt-bt2)/ctrcout cout cincont/*void FCFSgantt() */Limitations In FCFS, fair waiting time is quite monthlong. If we have a processor forswear job (generally with longer service time) and other I/O stand out 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. exchangeable in the test cases we observed, process P3 notwithstanding having a very short service time had to wait for long till all the processes ahead of it ran to completion. ordin ary Turn around Time 12Average Waiting Time 7.2Average Response Time 7.26.2. ROUND ROBINThe round-robin (RR) scheduling algorithm is designed especially for time-sharing systems. It is homogeneous 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 altogether present the main part of the programme./* Programme for ROUND ROBIN*/f or(i=0jif(ri0sp=ai)f=trueif(ritime=rielse time=q//schedule the processti+=time,ri=time,order.push_back(i+1)if(ri==0) j++ for(k=0kif(rk=0k=iakif((akwk+=sp+time-ak,ti+=sp+timeakelsewk+=time,tk+=timesp+=timecontinueif(i==n-1)if(f)int itint diff=0for(it=0itif(spif(diff==0) diff=ait-spelse if(diffait-sp) diff=aitspsp+=difff=falseOUTPUT-Advantages-Round Robin algorithm exhibits fair play. All the processes are treated equally and are given equal processor time. As compared to FCFS, the mediocre waiting time is considerably reduced in Round Robin algorithm.Limitations The performance of the system implementing Round Robin generally depends upon the value of the quantum. If we set the quantum to very high value, then it will conk as the FCFS. As a result the system performance will be sluggish. If we keep the quantum value low, more overhead will be produced because of frequent context switch .Round Robin with low quantum is generally competent for the synergistic system. However, to determine the optimal quantum time is a tedious task6.3.SHORTEST JOB FIRSTA different approach to CPU scheduling is the shortest-job-first (SJF) scheduling algorithm. This algorithm associates with each process the length of the processs next CPU burst. When the CPU is available, it is assigned to the process that has the smallest next CPU burst. If the next CPU bursts of two processes are the same, FCFS scheduling is used to break the tie. Note that a more appropriate term for this scheduling method would be the shortest-next-CPU-burst algorithm, because scheduling depends on the length of the next CPU burst of a process, sooner than its gibeal length. The SJF algorithm is a special case of the general priority scheduling algorithm. A priority is associated with each process, and the CPU is allocated to the process with the highest priority. Equal-priority processes are scheduled in FCFS order. An SJF algorithm is simply a priority algorithm where the priority (p) is the inverse o f the (predicted) next CPU burst. The larger the CPU burst, the spurn the priority, and vice versa. C- programming for this scheduling algorithm is given below. I only present the main part of the programme./* Programme for SJF*/includeincludeincludevoid main()char p105,temp5int tot=0,wt10,pt10,i,j,n,temp1float avg=0clrscr()printf(enter no of processes)scanf(%d,n)for(i=0iprintf(enter process%d namen,i+1)scanf(%s,pi)printf(enter process time)scanf(%d,pti)for(i=0ifor(j=i+1jif(ptiptj)temp1=ptipti=ptjptj=temp1strcpy(temp,pi)strcpy(pi,pj)strcpy(pj,temp)wt0=0for(i=1iwti=wti-1+eti-1tot=tot+wtiavg=(float)tot/nprintf(p_namet P_timet w_timen)for(i=0iprintf(%st%dt%dn,pi,eti,wti)printf(total waiting time=%dn avg waiting time=%f,tot,avg)getch()Output Advantages Shorter processes are given preference. If the ready queue contains Processor bound processes and some I/O bound processes, then the I/O bound will be given more preference. As a result the system throughput increases.Average waiting tim e of the processes decreases. Like in the test case, the process P3 waited for only 6 seconds compared to 10 seconds in RR and 16 seconds in FCFS.6.4 .SHORTEST REMAINING TIME (SRT)This is the preemptive algorithm which acts on the principles of SPF. It gives preference to the processes with the smaller service time.If a process is using the process and in the mean time a new process arrives whose service time is less than the currently running, then it preempts the currently running process and gives processor control to the new process. This algorithm is no longer useful in todays operating systems.Advantages It offers the minimum waiting time for the processes. Like the process P3, waited for 6 seconds forwards getting the processor time. Though this waiting time is equal to that in SPF. notwithstanding being a preemptive algorithm, SRT gain ground over SPF by providing even lesser waiting time than the former.Average Turn around Time 11Average Waiting Time 6.4Average Response Time 66.5 HIGHEST RESPONSE RATIO borderingThis algorithm corrects some of the weakness of the SPF. The SPF algorithm is biased towards the processes with short service time. This keeps the longer processes waiting in the ready queue for the longer time, in spite of of arriving in the ready queue before the short jobs.It is a non-preemptive scheduling algorithm in which the priority is the function of not only the service time but also of the time spent by the process waiting in the ready queue. Once the process obtains the control of the processor, it completes to completion. The priority is calculated by the formulaPriority = (Waiting Time + Service Time)/Service TimeIn this algorithm too, short processes receive preference. But longer processes that have been waiting in the ready queue are also given the favorable treatment.7.GRAPHICAL REPRESENTATIONTurnaround Time ComparisonWaiting time comparisonResponce time comparison8.CONCLUSIONFrom the analysis of the algorithms, we have come up with the conclusion that RR has the best average response time and being the preemptive algorithm, it exhibits fairness. But however, performance of the RR algorithm depends heavily on the coat of the quantum. On the one extreme is the time quantum is very large, RR algorithm is same as FCFS policy. But if the time quantum is fairly small, the RR will exhibit fairness but a considerable overhead gets added to the turnaround time overdue frequent context switch.This fact becomes clear from the RR average turnaround time reading is highest as compared to other algorithms. Hence we observed if majority of the processes are less then the time quantum, the RR will give better response time.Further, SPF has the least average turnaround time and average waiting time as compared to other algorithms.This shows that SPF is provably optimal, in that it gives the minimum average time in the set of processes by moving the short process before a long one. The waiting time of short proce ss decreases more than the waiting time of the long process. Consequently the waiting time decreases. But this algorithm can only be used for systems which are synergetic and thereby is biased to short processes and unfavorable to longer ones which may course to indefinite postponement of longer processes.HRRN has approximately same average turnaround, waiting and response time. It overcomes the limitation of the SPF by giving favorable treatment to the processes waiting for a longer time, and thereby prevents indefinite postponement.SRT exhibits approximately same average response time, waiting time and turnaround time, and may seem to be an effective algorithm for interactive processes if the tasks performed before issuing I/O are short in duration. However, SRT determines priority based on the run time to completion, not the run time to I/O. Some interactive processes such as instance executes for the life time of the session, which would place the shell at the lowest priority level.

No comments:

Post a Comment