A Primer on Process Scheduling [Operating Systems]

How does process get executed? How are processes scheduled?

Important Terms

  • Burst Time/Execution Time:
    It is a time required by the process to complete execution. It is also called running time.
  • Arrival Time:
    When a process enters in a ready state
  • Finish Time:
    When process complete and exit from a system
  • Multiprogramming:
    A number of programs which can be present in memory at the same time.
  • Jobs:
    It is a type of program without any kind of user interaction.
  • User:
    It is a kind of program having user interaction.
  • Process:
    It is the reference that is used for both job and user.
  • CPU/IO burst cycle:
    Characterizes process execution, which alternates between CPU and I/O activity. CPU times are usually shorter than the time of I/O.

Objective of Process Scheduling

  • Maximise
    • Max CPU utilization
      Keep CPU as busy as possible (Fair allocation of CPU)
    • Max throughput
      Number of processes that complete their execution per time unit
  • Minimise
    • Min turnaround time
      Time taken by a process to finish execution
    • Min waiting time
      Time a process waits in ready queue
    • Min response time
      Time when a process produces first response

Scheduling Queues

Scheduling Queues
Scheduling Queues

  • Job queue − This queue keeps all the processes in the system.
  • Ready queue − This queue keeps a set of all processes residing in main memory, ready and waiting to execute. A new process is always put in this queue.
  • Device queues − The processes which are blocked due to unavailability of an I/O device constitute this queue.

Schedulers

Long-Term SchedulerShort-Term SchedulerMedium-Term Scheduler
It is a job schedulerIt is a CPU schedulerIt is a process swapping scheduler.
Speed is lesser than short term schedulerSpeed is fastest among other twoSpeed is in between both short and long term scheduler.
It controls the degree of multiprogrammingIt provides lesser control over degree of multiprogrammingIt reduces the degree of multiprogramming.
It is almost absent or minimal in time sharing systemIt is also minimal in time sharing systemIt is a part of Time sharing systems.
It selects processes from pool and loads them into memory for executionIt selects those processes which are ready to executeIt can re-introduce the process into memory and execution can be continued.

Context Switching

Context Switch
Context Switch

Scheduling Algorithms

Scheduling Algorithms
Scheduling Algorithms

Preemptive Vs Non-preemtive

Preemptive SchedulingNon-preemptive Scheduling
A processor can be preempted to execute the different processes in the middle of any current process execution.Once the processor starts its execution, it must finish it before executing the other. It can’t be paused in the middle.
CPU utilization is more efficient compared to Non-Preemptive Scheduling. Waiting and response time of preemptive scheduling is less.CPU utilization is less efficient compared to preemptive Scheduling. Waiting and response time of the non-preemptive Scheduling method is higher.
Preemptive Scheduling is prioritized. The highest priority process is a process that is currently utilized.When any process enters the state of running, the state of that process is never deleted from the scheduler until it finishes its job.
In this process, the CPU is allocated to the processes for a specific time period.In this process, CPU is allocated to the process until it terminates or switches to the waiting state.
Examples: - Shortest Remaining Time First, Round Robin, etc.Examples: First Come First Serve, Shortest Job First, Priority Scheduling, etc.