Skip to main content

Priority scheduling


Priority scheduling

  •          In priority scheduling , a priority is associated with all processes.
  •           Process are executed in sequence according to their priority.
  •          The CPU time is allocated to the process with highest priority.
  •          If the priority of two or more processes are equal than the process that has been inserted first  into  the ready queue is selected for execution. In other words, FCFS scheduling is performed when wo or more processes have same priority.
  •          The priorities are implemented as affixed range of numbers such as 0to 7 or 0 to 4,095.
  •          In other system, a low number indicates a high priority . in that case,a process with priority 0 is executed first.
  •          Priorities can be defined in two ways : internal or externall.
  •          Priority scheduling can be preemptive or non preemptive.

  1.          In preemptive priority scheduling, scheduler allocates the CPU to the new process if the priority of new process is higher than priorityof the running process.
  2.           In non-preemptive priority scheduling, the running process is not interrupted even if new process has a higher priority. In this case the new process will be placed at the head of ready queue.

               

Characteristics of Priority Scheduling

  • A CPU algorithm that schedules processes based on priority.
  • It used in Operating systems for performing batch processes.
  • If two jobs having the same priority are READY, it works on a FIRST COME, FIRST SERVED basis.
  • In priority scheduling, a number is assigned to each process that indicates its priority level.
  • Lower the number, higher is the priority.
  • In this type of scheduling algorithm, if a newer process arrives, that is having a higher priority than the currently running process, then the currently running process is preempted.

Example of Priority Scheduling

Consider following five processes P1 to P5. Each process has its unique priority, burst time, and arrival time.

ProcessPriorityBurst timeArrival time
P1140
P2230
P3176
P43411
P52212

Step 0) At time=0, Process P1 and P2 arrive. P1 has higher priority than P2. The execution begins with process P1, which has burst time 4.

Step 1) At time=1, no new process arrive. Execution continues with P1.

Step 2) At time 2, no new process arrives, so you can continue with P1. P2 is in the waiting queue.

Step 3) At time 3, no new process arrives so you can continue with P1. P2 process still in the waiting queue.

Step 4) At time 4, P1 has finished its execution. P2 starts execution.

Step 5) At time= 5, no new process arrives, so we continue with P2.

Step 6) At time=6, P3 arrives. P3 is at higher priority (1) compared to P2 having priority (2). P2 is preempted, and P3 begins its execution.

ProcessPriorityBurst timeArrival time
P1140
P221 out of 3 pending0
P3176
P43411
P52212

Step 7) At time 7, no-new process arrives, so we continue with P3. P2 is in the waiting queue.

Step 8) At time= 8, no new process arrives, so we can continue with P3.

Step 9) At time= 9, no new process comes so we can continue with P3.

Step 10) At time interval 10, no new process comes, so we continue with P3

Step 11) At time=11, P4 arrives with priority 4. P3 has higher priority, so it continues its execution.

ProcessPriorityBurst timeArrival time
P1140
P221 out of 3 pending0
P312 out of 7 pending6
P43411
P52212

Step 12) At time=12, P5 arrives. P3 has higher priority, so it continues execution.

Step 13) At time=13, P3 completes execution. We have P2,P4,P5 in ready queue. P2 and P5 have equal priority. Arrival time of P2 is before P5. So P2 starts execution.

ProcessPriorityBurst timeArrival time
P1140
P221 out of 3 pending0
P3176
P43411
P52212

Step 14) At time =14, the P2 process has finished its execution. P4 and P5 are in the waiting state. P5 has the highest priority and starts execution.

Step 15) At time =15, P5 continues execution.

Step 16) At time= 16, P5 is finished with its execution. P4 is the only process left. It starts execution.

Step 17) At time =20, P5 has completed execution and no process is left.

Step 18) Let's calculate the average waiting time for the above example.

Waiting Time = start time - arrival time + wait time for next burst

P1 = o - o = o
P2 =4 - o + 7 =11	
P3= 6-6=0
P4= 16-11=5
Average Waiting time = (0+11+0+5+2)/5 = 18/5= 3.6

Advantages of priority scheduling

Here, are benefits/pros of using priority scheduling method:

  • Easy to use scheduling method
  • Processes are executed on the basis of priority so high priority does not need to wait for long which saves time
  • This method provides a good mechanism where the relative important of each process may be precisely defined.
  • Suitable for applications with fluctuating time and resource requirements.

Disadvantages of priority scheduling

Here, are cons/drawbacks of priority scheduling

  • If the system eventually crashes, all low priority processes get lost.
  • If high priority processes take lots of CPU time, then the lower priority processes may starve and will be postponed for an indefinite time.
  • This scheduling algorithm may leave some low priority processes waiting indefinitely.
  • A process will be blocked when it is ready to run but has to wait for the CPU because some other process is running currently.
  • If a new higher priority process keeps on coming in the ready queue, then the process which is in the waiting state may need to wait for a long duration of time.

Summary:

  • Priority scheduling is a method of scheduling processes that is based on priority. In this algorithm, the scheduler selects the tasks to work as per the priority.
  • In Priority Preemptive Scheduling, the tasks are mostly assigned with their priorities.
  • In Priority Non-preemptive scheduling method, the CPU has been allocated to a specific process.
  • Processes are executed on the basis of priority so high priority does not need to wait for long which saves time
  • If high priority processes take lots of CPU time, then the lower priority processes may starve and will be postponed for an indefinite time.

 

Comments

Popular posts from this blog

Batch Processing Operating System

  Batch processing system ·           Batch processing is one of the oldest method    of running the programs ·           The computer in the past were very large in size and their I/O devices were very different from those that are used today. The job processing was not interactive as it is today. ·           The user did not interact directly with computer system.   ·           The process scheduling , memory management, file management and I/Omanagement functions are quite simple in batch processing system   1.         Process scheduling (i.e. allocation strategy for a processor is typically in order of their arrival i.e. first come first served(FCFS)basis.   2.         Memory management  is done by divi...

Multitasking System

  Multitasking system ·           Technically , multitasking is same as multi programming ·           In a multitasking operating system, s single user can execute multiple programs at the same time ·           We can also say, multitasking is the system capability to work on more than one job or process at the same time. ·           It means that whenever a job needs to perform I/O operation, the cpu can be used for execting some other job                                                        diagram of multi tasking     ·           There are two type of multitasking : 1.       ...

Monolithic Architecture

  Monolithic Architecture Monolith means composed all in one piece. The  Monolithic  application describes a single-tiered  software  application in which different components combined into a single program from a single platform. Components can be: Authorization — responsible for authorizing a user Presentation — responsible for handling HTTP requests and responding with either HTML or JSON/XML (for web services APIs). Business logic — the application’s business logic. Database layer — data access objects responsible for accessing the database. Application integration — integration with other services (e.g. via messaging or REST API). Or integration with any other Data sources. Notification module — responsible for sending email notifications whenever needed. Example for Monolithic Approach Consider an example of Ecommerce application, that authorizes customer, takes an order, check products inventory, authorize payment and ships ordered products. This applicat...

Exokernel architecture

Exokernel architecture Most of us know what kernels are and how do they work to make programmers’ lives easier. But, how many of us know what exokernels are? I hope you will be able to get a brief introduction on this terminology through this blog. Let’s start with a brief introduction on kernel. What is a kernel? A kernel is the foundational layer of an operating system that functions at a basic level, communicating with hardware and managing resources, such as CPU and the memory. It works as an interface between the user application and the hardware. There   are two main types of kernel 1. Micro kernel 2. Monolithic Kernel 1.  Monolithic architecture 2.      Layerd archtecture . 3.       Virtual machine architecture 4.       Exokernel architecture 5.      Client server architecture   6.       Micro kernel architecture Now let’s head into our main focus. What is an Exokern...

Change the priority of a process

  Change the priority of a process You can tell the computer that certain processes should have a higher priority than others, and so should be given a bigger share of the available computing time. This can make them run faster, but only in certain cases. You can also give a process a  lower  priority if you think it is taking up too much processing power. Go to the  Processes  tab and click on the process you want to have a different priority. Right-click the process, and use the  Change Priority  menu to assign the process a higher or lower priority. There is typically little need to change process priorities manually. The computer will usually do a good job of managing them itself. (The system for managing the priority of processes is called  nice .) Does higher priority make a process run faster? The computer shares its processing time between all of the running processes. This is normally shared intelligently, so programs that are doing more ...