100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C

Introduction to Process Scheduling

Learn why the OS schedules processes, the queues involved, and the basic goals of a scheduler.

Process ManagementBeginner9 min readJul 8, 2026
Analogies

Introduction

A multiprogrammed operating system keeps several processes in memory at once so the CPU is never idle: whenever one process must wait (for I/O, for example), the OS switches the CPU to another process that is ready to run. Process scheduling is the activity of deciding which ready process gets the CPU next, and it is the mechanism that turns a single CPU (or a small number of cores) into the illusion of many processes running simultaneously.

🏏

Cricket analogy: A stadium keeps multiple net-practice sessions going so no bowling lane sits idle: when one batter takes a drinks break, the coach immediately sends in the next batter, just as multiprogramming swaps in a ready process whenever another blocks on I/O.

Explanation

The OS maintains scheduling queues to organize processes: the job queue holds all processes in the system, the ready queue holds processes in memory that are ready and waiting to execute, and device queues hold processes waiting for a particular I/O device. A process migrates among these queues as it changes state. The component responsible for choosing which process in the ready queue runs next is called the short-term scheduler (or CPU scheduler), and it runs very frequently — potentially many times per second. A long-term scheduler (present in some systems, especially batch systems) controls the degree of multiprogramming by deciding which jobs are admitted into memory. Scheduling goals typically include maximizing CPU utilization, maximizing throughput (processes completed per unit time), minimizing turnaround time (total time from submission to completion), minimizing waiting time (time spent in the ready queue), and minimizing response time (time from submission until the first response), though different systems prioritize these goals differently depending on whether they are batch, interactive, or real-time systems.

🏏

Cricket analogy: The team's full touring squad is the job queue, the players padded up and waiting near the boundary rope are the ready queue, and those waiting for a specific net or physio session are device queues; the team manager (short-term scheduler) decides who bats next almost every over, while the selection committee (long-term scheduler) decides who even makes the touring squad.

Example

c
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

/* Spawns several children that are all 'ready' at roughly the same time,
   illustrating that the OS scheduler decides their execution order. */
int main(void) {
    const int n = 3;
    for (int i = 0; i < n; i++) {
        pid_t pid = fork();
        if (pid == 0) {
            /* Each child is CPU-bound briefly, then exits */
            printf("Child %d (PID %d) is now Ready/Running\n", i, getpid());
            volatile long sum = 0;
            for (long j = 0; j < 100000000L; j++) sum += j;
            printf("Child %d (PID %d) finished\n", i, getpid());
            _exit(0);
        }
    }
    for (int i = 0; i < n; i++) {
        wait(NULL);
    }
    printf("Parent: all children scheduled and completed\n");
    return 0;
}

Output

The order in which 'Child N finished' lines appear is not guaranteed to match creation order — it depends entirely on how the short-term scheduler interleaves the three ready processes across available CPU cores and time slices. On a multi-core machine some children may run truly in parallel; on a single core, the scheduler time-slices between them. This demonstrates that scheduling policy, not program order, determines actual execution order among ready processes.

🏏

Cricket analogy: Three batters padded up don't necessarily go out to bat, retire, or get out in the order they arrived at the ground -- the umpire's and captain's real-time decisions on the field determine the actual sequence, not who arrived first.

Key Takeaways

  • Process scheduling decides which ready process gets the CPU next, enabling multiprogramming.
  • The short-term (CPU) scheduler runs frequently and picks from the ready queue.
  • The long-term scheduler, where present, controls how many processes are admitted into memory.
  • Scheduling goals include CPU utilization, throughput, turnaround time, waiting time, and response time.
  • Different systems (batch, interactive, real-time) weigh these goals differently.

Practice what you learned

Was this page helpful?

Topics covered

#OperatingSystemsStudyNotes#OperatingSystems#IntroductionToProcessScheduling#Process#Scheduling#Explanation#Example#StudyNotes#SkillVeris#ExamPrep