Asia Pacific Journal of Engineering Science and Technology 3 (2) (2017) 76-85 Asia Pacific Journal of Engineering Science and Technology journal homepage: www.apjest.com Full length article Analysis, implementation and simulation of different CPU scheduling algorithms Avinash Balodiya 1, Amit Kumar Sharma 2,*, Arvind Balodiya 3 1,2 Department CSE, The ICFAI University, Jaipur, India 3 Oracle Hyderabad, India (Received 24 March 2017; accepted 9 June 2017; published online 25 June 2017) ABSTRACT In the Operating System, resources are required to use efficiently and effectively. To fulfill this objective various types of scheduling algorithms exist to decide how and in which order process should be executed. The main objective of this paper is to introduce experimental analysis of CPU Scheduling algorithms. This paper gives an overview of various CPU Scheduling algorithms such as First Come First Serve (FCFS), Shortest Job First (SJF), Priority Scheduling Algorithm (PJF), Round Robin Scheduling Algorithm (RR) followed by comparison of all these algorithms on different parameters. In addition, this paper is mainly focuses on implementation and simulation of all these algorithms on GUI interface software called Inside My Machine. Keywords: CPU Scheduling; First-Come-First-Served; Shortest Job First; Priority Scheduling; Round Robin; Inside My Machine 1. Introduction CPU Scheduling is an important task of an operating system. In this paper we are trying to focus on comparison of different CPU Scheduling algorithms and also implementing a software name given is Inside My Machine. This software is made in JAVA programming language. Software helps to understand the working of different scheduling algorithms. Overview of operating systems and different CPU scheduling algorithms 1.1 Operating System An Operating System is an software, that manages the computer hardware and application software [1]. It can be seen as software which acts as an interface between the user and the hardware [1]. Operating System manages computer hardware and provides convenient environment for the execution of the process [1]. Different types of tasks are performed by * E-mail address: amitchandnia@gmail.com 2017 Author(s)
77 A. Balodiya et al. Asia Pacific J. Eng. Sci. Tech. 3 (2) (2017) 76-85 Operating System and one of them is resource allocation. Thus, the Operating System is also known as Resource Allocator [1]. The hardware must provide appropriate mechanisms to ensure the correct operation of the computer system and to prevent user programs from interfering with the other operation of the system. 2. Introduction to CPU scheduling CPU Scheduling is defined as the process of allocating CPU to different process for a specified period of time [1]. CPU Scheduling forms the basis of multi-programmed operating systems [1, 2]. Through the use of CPU Scheduling the computer can be more productive and effectively utilized. 2.1 Why Scheduling Required? The selection of process to CPU allocation is not easy as it seems. There is need of CPU scheduling algorithms to solve the problem of allocating CPU to Process for its execution [1]. CPU scheduling helps in accomplishing operating system to make the best utilization of CPU. 2.2 Scheduling Criteria These Scheduling algorithms are different in terms of their characteristics. Different scheduling algorithms have different nature. Performance of these scheduling algorithms varies in different situation. However, the comparison between these algorithms includes the following Scheduling Criteria to compare [1, 3]: Throughput: Maximize the number of jobs processed per hour. Turn Around time: The time between a process execution to the time of completion. Waiting time: Waiting Time is defined as Sum of times spent in ready queue. Response Time: Time from submission till the first response is produced, minimize response time for interactive users. Utilization: How much the CPU Utilized, the main goal is to make CPU utilized efficiently at every point. Fairness: It makes sure that each process gets a fair share of the CPU. 3. CPU Scheduling algorithms 3.1 First-Come-First-Served Scheduling (FCFS) First-Come-First-Served Scheduling is one of the simplest algorithm for CPU scheduling but not the effective one. FCFS is non preemptive in nature [1, 2]. In this algorithm, the process who requests the CPU first is executed first i.e. the process executed in the order they arrive. The disadvantage of this algorithm is that the average waiting time is too large. If a process with long burst time comes then it makes the CPU busy for a long period of time. So, FCFS not a good algorithm in time sharing systems.
78 A. Balodiya et al. Asia Pacific J. Eng. Sci. Tech. 3 (2) (2017) 76-85 3.2 Shortest-Job-First Scheduling (SJF) Shortest-Job-First Scheduling is the scheduling algorithm that selects the process having smallest burst time. It is an optimal algorithm. The problem associated with this algorithm is to know the length of next CPU burst. The SJF cannot be implemented in short term scheduling because it s not possible to know the length of next CPU burst in that case. SJF is of two types preemptive or non-preemptive. The preemptive SJF is known as Shortest Remaining Time First Scheduling [1]. 3.3 Priority Scheduling Algorithm (PJF) Priority Based Scheduling is a scheduling algorithm which includes priority associated with each process [1, 2, and 3]. The processes having the highest priority are executed first and processes having lower priority are executed in the end. However, in two process that having the same priority, the FCFS used to select the process for execution first [1]. 3.4 Round-Robin Scheduling (RR) Round-Robin Scheduling is another scheduling algorithm its working is similar to FCFS but it includes time quantum. It is the most widely used algorithm for CPU scheduling [1] and it especially use for time sharing systems. In RR scheduling, the CPU is allocated to the first process in the queue for q (time quantum) time units. After q time units, if the process has not free the CPU, then it is preempted, and the process is put at the tail of the ready queue [1, 3]. But choosing the right time quantum is necessary if we use too small time quantum then context switching takes place many time similarly, on the other hand if we choose quantum too large response time becomes long and shows slow responses for user actions. 4. Comparison of Scheduling Algorithms CPU Scheduling algorithms are compared for knowing the best algorithm for a specific requirement. The following table shows comparison of scheduling algorithms on different parameters such as Throughput, Turnaround time, Response Time etc. [1, 2, 3, 6, 7 and 8]
79 A. Balodiya et al. Asia Pacific J. Eng. Sci. Tech. 3 (2) (2017) 76-85 Table 1 Comparison table S. Parameter FCFS SJF Priority Round Robin No. 1. Throughput Low High Low Medium 2. Turn High Medium High Medium Around Time 3. Response Time Low Medium High High CPU CPU allocated CPU allocated to CPU allocated CPU allocated in 4. Allocation to process in process having to higher priority FCFS way but order they least burst time basis process with preemption arrives 5. Preemptive Non- Preemptive Preemptive Preemptive preemptive 6. CPU Low Medium Medium High Utilization 7. Difficulty Simplest Difficult Difficult Difficult 5. Related work This paper shows the comparison of different algorithms along with their comparison. However, it not gives too much detail about scheduling algorithms. To understanding Scheduling algorithms [3] State diagrams used so that it will easier for user to understand the CPU algorithms and helps to choose a scheduling algorithm in a particular case. This one can be seen as a new approach to [4] compare the different scheduling algorithms has through graphical representation which gives a better understanding regarding how will the selected algorithm will behave in a particular situation. 6. Proposed software inside my machine Inside My Machine, basically is software that provides a GUI interface. Through this software, a user enable to give information related to process then applying different algorithms by selecting algorithm choices given in the Inside My Machine. Inside My Machine is GUI Interface software which is completely made on JAVA Platform. It shows the Gantt chart of scheduling algorithms and calculates the average waiting time. The software is able to explain the working of different scheduling algorithms. Through this software, the user can easily understand the order of a given number of processes which got executed along with the waiting
80 A. Balodiya et al. Asia Pacific J. Eng. Sci. Tech. 3 (2) (2017) 76-85 time of each process in the queue. The experimental results of these different scheduling algorithms can be seen with this software. 7. Implementation 7.1 Working Of Inside My Machine The working process of Inside My Machine is explained as in the following steps: Step 1: Fig. 1 shows the Home screen of Inside My Machine in which user can enter no. process in two ways 1. By entering process related data such as arrival time, CPU Burst etc manually. 2. By Filling the data randomly (going through the options menu and selecting randomly option). Fig. 1 Home Screen of Inside My Machine Step 2: Once the user entered the details he can switch to any of algorithm result by clicking the on the buttons. Fig.2 shows the Gantt chart of the Arrival Time, Burst Time and Waiting Time. This Screenshot shows the FCFS algorithm working.
81 A. Balodiya et al. Asia Pacific J. Eng. Sci. Tech. 3 (2) (2017) 76-85 Fig. 2 FCFS algorithm Result Step 3: Similarly, the Fig. 3 shows the Gantt chart and total time for SJF (preemptive). Fig. 3 SJF algorithm Result
82 A. Balodiya et al. Asia Pacific J. Eng. Sci. Tech. 3 (2) (2017) 76-85 Step 4: In the same way we can get the result for other algorithms like Round Robin, Priority scheduling etc in Inside My Machine. Fig. 4 General flowchart of Inside My Machine 7.2 Pseudo code for appending non prior process Whenever a new process P comes in Queue called Processes. If(size==0) Processes.head= Processes [0]=P; If(size>1) For i = 0 to i < size If (compareprocessbycpuburst(processes[i],p)<0) P.next = Processes[i]; If(i==0) Processes.head = P; Else
83 A. Balodiya et al. Asia Pacific J. Eng. Sci. Tech. 3 (2) (2017) 76-85 Processes[i-1].next=P; Break; End for End If 7.3 Pseudo code for appending priority process Whenever a new process P comes in Queue called Processes. If Priority is being taken on scale of 0-10, Process with 0 priority value will be considered of highest priority. If(size==0) Processes.head= Processes[0]=P; If(size>1) For i = 0 to i < size If compareprocessbypriority(processes[i],p)<0) P.next = Processes[i]; If(i==0) Processes.head = P; Else Processes[i-1].next=P; Break; End for End If 7.4 Algorithm for FCFS Whenever a new process P comes in Queue called Processes, it will be appended into Queue at last Processes. enqueue (P); Waiting time of any Process in queue will be calculated as Processes [i].waitingtime= Processes [0 to i-1].cpuburst 7.5 Algorithm for SJF Whenever a new process P comes in Queue called Processes, it is compared with the existing process Q having CPU allocated. If Preemption is allowed the process P will be given CPU and process Q will be added in the queue at appropriate place using previous algorithm. The comparison pseudo code is given below. compareprocessbycpuburst (Pi, Pj){ if(pi.cpuburst==pj.cpuburst) return0; else if(pi.cpuburst<pj.cpuburst)
84 A. Balodiya et al. Asia Pacific J. Eng. Sci. Tech. 3 (2) (2017) 76-85 } return -1; else rerurn 1; compareprocessbypriority (Pi, Pj){ if(pi.cpuburst==pj.cpuburst) return0; else if(pi.cpuburst<pj.cpuburst) return -1; else rerurn 1; } 8. Conclusion and future work Operating System can be defined as software that acts as an intermediary between the software and hardware. There are many functions that can an Operating system performed and one of them is CPU Scheduling. Many algorithms are used for CPU scheduling but all of them have some advantages and disadvantages. FIFO is easy to implement but gives large average time. SJF is optimal but in this you can t predict how long will the next CPU burst. Priority Scheduling has linked with problem of Starvation and in round robin quantum selection is a problem. None of them stands as ideal scheduling algorithm but every scheduling algorithm has specifies it own use in a selected requirement. Inside My Machine, JAVA based software, provides GUI interface to understand the working of scheduling algorithms. Inside My Machine successfully shows the experimental results of scheduling algorithms. In the future work other Operating System algorithms such as Deadlock and page replacement algorithms etc. will also be included in Inside My machine. References [1] A. Silberschatz, P.B. Galvin and G. Gagne, Operating System Concepts, 8th edition, Wiley India, 2012. [2] A. Bhardwaj, R. Singh, Gaurav, Comparative Study of Scheduling Algorithms in Operating System, International Journal of Computers and Distributed Systems, 3 (1), 2013, pp. 5-7. [3] N. Goel, R.B. Garg, A Comparative Study of CPU Scheduling Algorithms, IJGIP, 2 (4), 2012, pp. 245-251. [4] P. Singh, V. Singh, A. Pandey, Analysis and Comparison of CPU Scheduling Algorithms, 4 (1) 2014, pp. 91-95. [5] https://www.cs.uic.edu/~jbell/coursenotes/operatingsystems/5_cpu_scheduling.html.
85 A. Balodiya et al. Asia Pacific J. Eng. Sci. Tech. 3 (2) (2017) 76-85 [6] E.D. Jensen, C.D. Locke, H. Tokuda, A Time-Driven Scheduling Model for Real-Time Operating Systems, CH2220-2/85/OOOO/011 2$01.0001985 IEEE. [7] R.K. Yadav, A.K Mishra, N. Prakash and H. Sharma, An Improved Round Robin Scheduling Algorithm for CPU scheduling, International Journal on Computer Science and Engineering, 2 (4) 2010, pp. 1064-1066. [8] M. Sindhu,R. Rajkamal, P.Vigneshwaran, An Optimum Multilevel CPU Scheduling Algorithm, DOI: 10.1109/ACE.2010.14, IEEE Xplore.