PreprintPDF Available

New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK)

Authors:
  • Northern Technical University location Mosul, Iraq
Preprints and early-stage research may not have been peer reviewed yet.

Abstract

The concept of processes scheduling has had a major role since the advent of operating scheduling policies, the CPU plays a significant role in the computer system by transferring control between different processes and must work efficiently, the operating system performs a basic task, which is scheduling the processor for its efficient and optimized use. Scheduling the processor is one of the most important operational implemented through the operating system. Different algorithms for processor scheduling exist including the scheduling algorithm of priority. The priority number makes the algorithm effective. In this research, a proposed algorithm for scheduling the processor between processes was adopted using the KNAPSACK algorithm in order to eliminate the waiting state and starvation situation that occurs for low priority processes.
GRD Journals- Global Research and Development Journal for Engineering | Volume 5 | Issue 6 | May 2020
ISSN- 2455-5703
All rights reserved by www.grdjournals.com
24
New Optimized Priority CPU Scheduling
Algorithm by using Knapsack (NOPSACK)
Abdulrafa Hoseen Maree
Department of Computer Science and Engineering
Northern Technical University, Iraq
Najim Abdullah Tahhan
Maher Talal Alasaady
Department of Computer Science and Engineering
Department of Computer Science and Engineering
Northern Technical University, Iraq
Northern Technical University, Iraq
Abstract
The concept of processes scheduling has had a major role since the advent of operating scheduling policies, the CPU plays a
significant role in the computer system by transferring control between different processes and must work efficiently, the operating
system performs a basic task, which is scheduling the processor for its efficient and optimized use. Scheduling the processor is one
of the most important operational implemented through the operating system. Different algorithms for processor scheduling exist
including the scheduling algorithm of priority. The priority number makes the algorithm effective. In this research, a proposed
algorithm for scheduling the processor between processes was adopted using the KNAPSACK algorithm in order to eliminate the
waiting state and starvation situation that occurs for low priority processes.
Keywords- CPU Scheduling, Priority CPU Scheduling, Turnaround Time, Waiting Time, Context Switching, Gantt
Chart, Knapsack Algorithm, Starvation
I. INTRODUCTION
The operating system manages the hardware and software resources of the computer and execute different tasks. The processor
scheduling is considered a basic task. All resources are scheduled before use, that is to give them to processes as needed and at
new state in the life cycle of the process[3]. In the computer system, scheduling is the basic function of the operating system, a
process is selected from ready queue for implementation and by a short-term scheduler (STS)[9]. These algorithms are designed
to schedule processes in CPU, each one better than the others in some performance measures and each has its advantages and
disadvantages[10]. The proposed algorithm (NOPSACK) is a priority algorithm using a KNAPSACK algorithm by obtaining
optimal results for any given problem[10], in order for the proposed algorithm to be more specific, relying on continuous or
fractional knapsack algorithm by dividing process execution time and using the ratio between values(v) and weights(w), v/w[10].
II. SCHEDULING CRITERIA
CPU scheduling algorithm have different features and characteristics, and the decision is made to choose the process for execution
and depending on different measures, these measures are used to compare different algorithms [1][3][6][7][9][11][12][13]. The
scheduler is concerned with [2][3][6][7][11] [12]:
A. CPU Utilization
Exploit all CPU time optimally in process executing, so cpu remains as busy as possible for being precious time.
B. Throughput
Number of processes completed within a specified period of time.
C. Turnaround Time (TAT)
Refers to the total time it takes to execute a particular process from the moment it enters the system into the moment the
execution ends[1][3][6][7][9][12][13], interspersed with time periods thereof[6]:
Wait before entering the memory.
Time in ready queue.
Time to execute the input and output operations.
It can be calculated as [9][11] :
TAT=Process completed time Process arrival time.
New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK)
(GRDJE/ Volume 5 / Issue 6 / 005)
All rights reserved by www.grdjournals.com
25
D. Waiting Time (WT)
The total time of the process in the ready queue, it can be calculated as [9][11] :
WT=TAT CPU execution time.
1) Response time
The time from taken the moment the process enters until the system makes the first response[12] .
2) Context Switch
Switch the CPU from one process to another. Performing fewer contexts switching for algorithms increase the system
performance[4].
So we conclude that a good scheduling algorithm must have following characteristics[6][9][11]:
CPU utilization ( Max.).
Throughput ( Max.).
Turnaround time ( Min.).
Waiting time ( Min.).
Response time ( Min.).
Context switches ( Min.).
III. SCHEDULING TYPES
Scheduling algorithms can be broadly categorized into [3][9][12][14][15]:
A. Preemptive Scheduling
The operating system remove the CPU for a specific reason from the process in progress, such as the arrival of a new process at
higher priority or shortest execution time, depending on the type of algorithm used[3][9][12][14].
B. Nonpreemptive Scheduling
The operating system does not remove the CPU from the process in progress and leaves it to the end of the time allocated for
execution, although a new process arrives at a higher priority or a shortest time process, and the CPU is automatically returned to
the system after the execution.
IV. SCHEDULERS TYPES
There are three types of schedulers [1][8][9] [10][12], they are:
A. Long- Term Scheduler (LTS)
It is named a JOB scheduler and is performed when new jobs are created. It is responsible for selecting jobs from the jobs pool and
loading them into main memory. It controls the number of processes in the main memory and is called a (degree of
multiprogramming) as in figure(1) [1], LTS executes much less frequently.
B. Short- Term Scheduler (STS)
It is named a CPU scheduler, selects the process from among these processes in ready queue in memory, which are ready to
execute. As in figure (1), the STS must be very fast[1].
Fig. 1: Scheduler and Queuing Diagram
C. Medium- Term Scheduler (MTS)
Remove processes temporarily from the main memory and puts them in the secondary memory and vice versa[12].
V. KNAPSACK PROBLEM
Problem occurs in combinatorial optimization, where there are a number of elements(n), for each of weight(w) and value(v) is
required to determine the number contained in the group of each element so that the total weight is less than or equal to the required
limit of the bag's capacity and the total value is as large as possible[5].
New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK)
(GRDJE/ Volume 5 / Issue 6 / 005)
All rights reserved by www.grdjournals.com
26
VI. KNAPSACK PROBLEM TYPES
A. Continuous Knapsack Problem
Elements are divisible; you can take any fraction of an element, also called Fractional knapsack, is a classic problem that can be
solved by greedy algorithms[5].
B. 0-1 Knapsack Problem
Elements are indivisible; you either take an element or not. Some special instances can be solved with dynamic programming[5].
VII. GREEDY ALGORITHM
There are more than one method:-
1) Max value(v).
2) Min weight(w).
3) Ratio (v/w).
Compute the ratio between the values and weights and then arrange them in descending order, fill the bag with the values and
weights corresponding to the largest percentage, and repeat it on condition that the total weights do not exceed the capacity of the
bag [5].
VIII. RELATED WORK DONE
In Neel sack algorithm[10] the idea of a knapsack problem is related to the concept of process scheduling. The knapsack weight
was considered as the CPU capacity, knapsack elements were considered to be processes and the element weight was considered
to be execution time, and also the element value was considered the priority given to process. The main subject of using the
similarity is that knapsack is designed to determine the best element for the thief to get the greatest profit, as well as the case of
CPU scheduling is the choice of the best process for the CPU by considering its priority.
IX. PROPOSED ALGORITHM (NOPSACK)
Fig. 2: The Flowchart Steps for (NOPSACK) Algorithm
New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK)
(GRDJE/ Volume 5 / Issue 6 / 005)
All rights reserved by www.grdjournals.com
27
The algorithm needs Parameters such as number of processes in queue, CPU execution time(Et) in addition to priority (Pri) for
each process. The CPU capacity(ß) can computed by dividing the sum of the execution time of all processes by the number of
processes(n) in the current iteration, ratio of process priority respective CPU execution time(v/w).
X. RULES AND ALGORITHM
1) No. of processes(n).
2) CPU execution time(Et).
3) Process priority(Pri).
Each process should get the processor. Steps:
1) Input No. of processes(n).
2) Respectively for each process, input CPU execution time(Et), Priority(Pri) .
3) Compute ratio (Pri/Et) for each process.
4) Processes are arranged in descending order depending on the ratio value.
5) Compute initial (ß) value (sum of execution time of all the processes(ɑ)/No. of processes(n) in the system).
6) Apply the knapsack algorithm by entering input parameters:
(n) No. of processes represent the knapsack elements.
(Et) CPU execution time represent the elements weight.
(Pri) Process priority represent the element cost.
7) Invert processes priority that got the processor in the current iteration, ( (Pri) value * (-1)) and cancel the processes were
completed.
8) Go-to step 5 (continue until all processes got CPU and completed execution).
9) Display and print result for each process.
The vital reason of the above steps to avoiding starvation of least priority processes unlike priority based scheduling[10].
XI. RESULT
Measurement parameters such as (TAT), (T) are considered, in different cases measured and compared with current scheduling
algorithms such as priority based and RR alg. . In order to verify the quality and efficiency of the algorithm, some of cases have
been shown, result of each iterations was analyzed and the last output was compared using the priority based and RR algorithm.
Case study: Sample 1: random cpu execution time with random priority Table 1[10], Five processes which have different cpu
execution time with different priority. Table 1: Input for sample 1
Initially calculation of ratio for each process, and arranged in descending order depending on ratio value.
Ratio=Priority(Pri)/CPU execution time(Et)[5].
=Value(v)/Weight(w) …………….. Equ.(1)
Capacity of Knapsack:
Where ɑ=Et
n−1
i=0
Iteration 1:
By applying knapsack algorithm using Equ.(2), Ƥ2,Ƥ3 were selected with the capacity ( 5 ) . Then priority of Ƥ2 and Ƥ3 has been
canceled shown below in the table 1(b) and so on with other iterations successively.
New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK)
(GRDJE/ Volume 5 / Issue 6 / 005)
All rights reserved by www.grdjournals.com
28
Table 1(a): for sample 1 with ratio value
Processes
Cpu
execution
time (w)
Ratio
(v/w)
P3
2
2
P2
3
1
P1
2
0.5
P4
6
0.3
P0
12
0.25
Our major idea is to approximate the computed ß value to the nearest smallest integer number, this approximate is done in order
for the value of capacity to be identical to the value of execution time without fractions.
Iteration 2:
ß=(2+6+12)/3=20/3=6.666=6
Iteration 3:
ß=(2+12)/2=14/2=7
Iteration 4:
ß=(2+5)/2=7/2=3.5=3
Iteration 5:
ß=(5)/1=5
Table 2: (c) Comparison of context switch for sample 1
Neelsack alg.
NOPSACK
6
6
Sample 2: randomly cpu execution time with equal priority
The work is similar to that in sample 1, table 3 [10], we have four processes, input has random cpu execution time but equal
priorities.
New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK)
(GRDJE/ Volume 5 / Issue 6 / 005)
All rights reserved by www.grdjournals.com
29
Fig. 3: sample (2) Gantt chart
Initially as sample 1 we compute ratio for each process and arranged in descending order depending on ratio value.
The computation is for capacity of knapsack
Iteration 1:
ɑ=(11+18+4+13)=46
ß=46/4=11.5=11
Iteration 2:
ɑ=(4+13+18)=35
ß=35/3=11.6=11
Iteration 3:
ɑ=(4+2+18)=24
ß=24/3=8
Iteration 4:
ɑ=(2+14)=16
ß=16/2=8
New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK)
(GRDJE/ Volume 5 / Issue 6 / 005)
All rights reserved by www.grdjournals.com
30
Iteration 5:
ɑ=14
ß=14/1=14
Fig. 4: sample (2) Gantt chart
Table 4: (c) Comparison of context switch for sample 2
Neelsack alg.
NOPSACK
7
6
XII. RESULT AND COMPARISON
Fig. 5: Result for sample 1
Fig. 6: Result for sample 2
New Optimized Priority CPU Scheduling Algorithm by using Knapsack (NOPSACK)
(GRDJE/ Volume 5 / Issue 6 / 005)
All rights reserved by www.grdjournals.com
31
As in the result for sample 1 as shown in the above Figure(5), the result of (TAT) and (WT) of NOPSACK is better than Neelsack
algorithm and other two algorithms ( RR , priority based ) . so this can describe that the NOPSACK algorithm can be implemented.
The result for sample 2 as shown in the above Figure(6), (TAT) of NOPSACK is same as Neelsack algorithm but (WT) and context
switches is less than Neelsack algorithm , also better than other two algorithms ( RR , priority based ) .
XIII. CONCLUSION
Algorithm NOPSACK it is better than few other algorithms, on the whole it is better than the RR alg. and priority based, but in
some cases they works best. Any algorithm is not the best in all situations. It is not possible to observe any scheduling algorithm
that works accurately, but accurate performance can be observed in live operating system operation. There are several factors that
have a significant impact on performance such as variable capacity selection and priority iversion and operators can be selected on
hardware configuration and process delivery mechanism used.
REFERENCES
[1] Ahmed M. Al-Safar (2012), "Hybrid CPU Scheduling algorithm SJF-RR in Static Set of Process", Al-Rafidain University College for Sciences , Issue:29,
Issn:16816870 , pp. 36-60.
[2] Amar R. Dash, Sandipta K. Sahu and Sanjay K. Samantra (February 2015),"An Optimized Round Robin CPU Scheduling Algorithm with Dynamic Time
Quantum", (IJCSEIT) International Journal of Computer Science Engineering and Information Technology, Vol. 5, No. 1, DOI:10.5121/ijcseit.2015.5102.
[3] Amit Kumar Sain (2013), “Dynamical Modified R.R. CPU Scheduling Algorithm", International Journal of Computer Trend and Technology, Volume 4,
Issue 2, PP. 90-93, ISSN:2231-2803.
[4] Muhammad A. , Bushra Hamid , Inayat Ur-Rehman , Mamoon H. , Maryam H. and Hira Khurshid (December 2015), " An Optimized Shortest job first
Scheduling Algorithm for CPU Scheduling", Journal of Applied Environmental and Biological Science, pp. 42-46 , ISSN:2090-4274, 5(12)42-46, Pakistan.
[5] E. M. Badr (2016), "Knapsack Problem", Information and Computer College, Banha University.
[6] Ishwari Singh and Deepa Gupta (Oct 2012)," A Priority based Round Robin CPU Scheduling Algorithm for Real Time System", (IJIET) International Journal
of Innovations in Engineering and Technology, Vol. 1, Issue 3, ISSN:2319-1058, India.
[7] Lipika Datta (June 2015), "Efficient Round Robin Scheduling Algorithm with Dynamic Time Slice", (IJEME) I.J.Education and Management Engineering,
pp. 10-19, DOI:10.5815/ijeme.2015.02.02 .
[8] N.Srilatha, SK.Mastanimurtazanaz and B.Ganga Bhavani (January 2018), "An Optimized Round Robin With Dynamic And Static Quanyum(ORDS)", (ijpam)
International Journal of Pure and Applied Mathematics, Volume 118, No. 16,pp. 243-252, ISSN:1311-8080(printed version);ISSN:1314-3395(on-line
version).
[9] Najim A. Al-Tahhan (April 2014),"Hybrid Algorithm for CPU Scheduling by Using Dynamic Time Quantum", Future Research Journal, Al-Hadba university
Collage, PP. 99-136, ISSN 1680-9300. Iraq .
[10] Neelakantagouda Patil (October 2015)," A Knapsack Based CPU Process Scheduling Using Neelsack Algorithm", (IJSEAS) International Journal of Scientific
Engineering and Applied Science,Volume-1, pp. 138-144, Issue-7, ISSN:2395-3470, India.
[11] Rashid Al Asif, Mehedi Raihan, Zakaria Hossain, Alam Hossain and Abdul Momin (December 2017), " Improved Performance of Round Robin CPU
Scheduling Algorithm Using Non-Preemptive SJF",(IJSER) International Journal of Scientific & Engineering Research, Volume 8, pp. 1,734-1,738, Issue
12, ISSN 2229-5518.
[12] Ryan R. Guadana, Maria R. Perez and Larry R. Jr.(January 2013), " A Comprehensive Review for Central Processing Unit Scheduling Algorithm" (IJCSI)
International Journal of Computer Science Issues, Vol 10, PP. 353-358, Issue 1, No 2, ISSN (Print):1694-0784; ISSN (Online):1694-0814.
[13] Siddharth Tyagi, Sudheer Choudhary and Akshant Poonia (October 2012), “Enhanced Priority Scheduling Algorithm to minimize Process Starvation",
(IJETAE) International Journal of Emerging Technology And Advanced Engineering", Volume 2, PP.288-294, Issue 10, ISSN 2250-2459, India.
[14] Sonia Z., Lotfi B. and Abdellatif Mtibaa (December 2016), "CPU Scheduling Algorithms: Case & Comparative Study",
https://www.researchgate.net/publication/317723403.
[15] Taqwa Flayyih Hasan (March 2014), "CPU SCHEDULING VISUALIZATION", Diyala Journal of Engineering Sciences, Vol. 07, No. 01, PP.16-29, ISSN
1999-8716, Iraq .
ResearchGate has not been able to resolve any citations for this publication.
Article
Full-text available
Scheduling is a key concept in computer multitasking and multiprocessing operating system design, and in real-time operating system design. CPU scheduling is the basis of multiprogramming operating systems by switching the CPU among process; the operating system can make the computer more productive, scheduling algorithms are widely used in communications networks and in operating systems to allocate resources to competing tasks. In this paper, visual interfaces for CPU scheduling algorithms were designed by using Visual Basic6 language. They may use to learn users about this algorithms and how they work.
Article
Full-text available
Modern operating systems switch from single task environment to multitask environment. Maximizing the resource utilization is the demand of today's computing. There are number of scheduling algorithms are available to schedule CPU resources. These algorithms are not implemented in a real time environment due to high context switching, high response time, large average waiting time, less throughput and large turnaround time. The objective of this paper is to develop a new approach for preemptive shortest job first which helps to improve the efficiency of CPU for real time and time sharing environment. The proposed approach improves the drawbacks of preemptive shortest job first scheduling algorithm. A comparative analysis of proposed algorithm is done with round robin and preemptive SJF algorithms. The comparison results show that the proposed algorithm improve the system performance by decreasing the context switching to a desirable extent.
Article
Full-text available
Round Robin (RR) scheduling algorithm is the widely used scheduling algorithm in multitasking. It ensures fairness and starvation free execution of processes. Choosing the time quantum in RR algorithm is very crucial as small time slice results in large number of context switches and large time quantum increases the response time. To overcome these problems of RR scheduling, instead of static time slice dynamic time slice can be used to get optimal performance. The objective of this paper is to modify RR algorithm by adjusting time slices of different rounds depending on the remaining CPU bursts of currently running processes and considering their waiting times until that round in respect of the other processes’ waiting times. Experimental analysis reveals that the proposed algorithm produces better average turnaround time, average waiting time and fewer number of context switches than existing algorithms.
Article
Full-text available
CPU scheduling is one of the most crucial operations performed by operating system. Different algorithms are available for CPU scheduling amongst them RR (Round Robin) is considered as optimal in time shared environment. The effectiveness of Round Robin completely depends on the choice of time quantum. In this paper a new CPU scheduling algorithm has been proposed, named as DABRR (Dynamic Average Burst Round Robin). That uses dynamic time quantum instead of static time quantum used in RR. The performance of the proposed algorithm is experimentally compared with traditional RR and some existing variants of RR. The results of our approach presented in this paper demonstrate improved performance in terms of average waiting time, average turnaround time, and context switching.
Article
Round Robin (RR) algorithm is widely used in modern operating systems (OS) as it has a better responsiveness as periodic quantum (occurring at regular intervals) in addition to have a good feature such as low scheduling overhead of n processes in a ready queue which takes a constant time O(1). But, RR algorithms have the worse features such as having low throughput, long average turnaround and waiting time, in addition to the number of context switches for (n) processes is (n) switches. Shortest Job First (SJF) however, itself is not practical in time sharing Oss due to its low response. More over the scheduling overhead of n processes in a ready queue is O(n), But the good features of SJF algorithm are the best average turnaround time and waiting time.By considering a static set of n processes, desirable features of CPU scheduler to maximize CPU utilization, response time and minimize waiting time and turnaround time are obtained by combining the kernel properties of SJF algorithm with the best features of RR algorithm to produce a new algorithm as an original and novel algorithm called; " Hybrid CPU Scheduling algorithm SJF-RR in Static Set of Processes " which, proposed in this research.The proposed algorithm is implemented through an innovative optimal equation to adapt time quantum factor for each process in each round as a periodic quantum (occurred at irregular intervals). That is while applying proposed algorithm, mathematical calculations take place to have particular time quantum for each process. Once, a criterion has been selected for comparison, deterministic modeling with the same numbers for input is proven that proposed algorithm is the best.
Article
The performance of multitasking operating system heavily depends on its scheduling algorithms. Round Robin is the most important part of CPU scheduling algorithm in the operating system where time quantum affects the performance. This algorithm is very useful for CPU scheduling that gives equal time quantum to all processes. This paper presents an improvement of RR CPU scheduling algorithm that reduces the average turnaround time, average waiting time and the number of context switches. The RR CPU scheduling algorithm with non-preemptive SJF method is applied for getting better performance. The proposed algorithm works as follows (i) Round Robin CPU scheduling algorithm is applied until all the processes arrive in the request queue, (ii) When all the processes are in the request queue then non-preemptive SJF is applied for remaining process execution. This proposed method increases the performance of RR CPU scheduling algorithm.
  • Amit Kumar Sain
Amit Kumar Sain (2013), "Dynamical Modified R.R. CPU Scheduling Algorithm", International Journal of Computer Trend and Technology, Volume 4, Issue 2, PP. 90-93, ISSN:2231-2803.
A Priority based Round Robin CPU Scheduling Algorithm for Real Time System
  • Ishwari Singh
  • Deepa Gupta
Ishwari Singh and Deepa Gupta (Oct 2012)," A Priority based Round Robin CPU Scheduling Algorithm for Real Time System", (IJIET) International Journal of Innovations in Engineering and Technology, Vol. 1, Issue 3, ISSN:2319-1058, India.
An Optimized Round Robin With Dynamic And Static Quanyum(ORDS)
  • N Srilatha
  • S K Mastanimurtazanaz
  • B Ganga Bhavani
N.Srilatha, SK.Mastanimurtazanaz and B.Ganga Bhavani (January 2018), "An Optimized Round Robin With Dynamic And Static Quanyum(ORDS)", (ijpam) International Journal of Pure and Applied Mathematics, Volume 118, No. 16,pp. 243-252, ISSN:1311-8080(printed version);ISSN:1314-3395(on-line version).