fortressystem@gmail.com +234 803 932 5001
Pen4tress ICT Academy
ICT Education

How Operating Systems Handle Process Scheduling and Memory Allocation

By pen4tress_admin July 27, 2026
How Operating Systems Handle Process Scheduling and Memory Allocation

How Operating Systems Handle Process Scheduling and Memory Allocation



At any given second, your computer or smartphone is juggling dozens of tasks simultaneously. You might be streaming a video in 4K, downloading a software update, editing a document, and running antivirus scans in the background—all without the system freezing up.



However, your computer’s CPU only has a finite number of physical cores, and your physical RAM has a strict capacity limit.



How does a system with an 8-core CPU run over 200 active processes seamlessly? The answer lies in the Operating System (OS), specifically its Process Scheduler and Memory Manager. Let's demystify how the OS manages compute time and memory without crashing.



1. Process Scheduling: Who Gets CPU Time?



A process is simply a program in execution. Because a single CPU core can only execute instructions for one process at a exact instant, the OS uses time-slicing to rapidly switch between tasks, creating the illusion that everything is running at once (multitasking).



To manage this queue, the OS kernel relies on Scheduling Algorithms.



Core CPU Scheduling Algorithms



1. First-Come, First-Served (FCFS)





2. Shortest Job First (SJF)





3. Round Robin (RR)





2. Context Switching: The Overhead Cost of Multitasking



When the scheduler pauses Process A to run Process B, it performs a Context Switch:




  1. Save State: The OS writes the current register values, instruction pointers, and stack pointers of Process A into its Process Control Block (PCB) in memory.

  2. Load State: The OS retrieves the PCB of Process B and loads its saved state back into the CPU registers.

  3. Resume: Execution continues for Process B right where it left off.



Key Trade-off: Context switches take time (~1 to 10 microseconds). If the time quantum in Round Robin is too short, the CPU spends more time switching between tasks than actually executing code—a performance degradation known as overhead.



3. Memory Allocation: Giving Processes Room to Work



Process scheduling gets CPU instructions executed, but programs also need memory to store active variables, data arrays, and UI elements.



If every program wrote directly to physical RAM wherever it pleased, a buggy app could overwrite another program's data—or worse, crash the Operating System entirely.



To prevent this, modern OS architectures implement Virtual Memory and Paging.



4. Virtual Memory and Paging Explained



Virtual Memory provides every application with the illusion that it has a massive, contiguous block of main memory all to itself.



How Paging Works




  1. Virtual Address Space: When a program starts, the OS assigns it virtual addresses starting from 0x0000. The program never knows where its data actually sits in physical hardware.

  2. Pages and Frames: The OS breaks memory down into fixed-size chunks:

    • Pages: Fixed blocks of Virtual Memory (typically 4 KB in size).

    • Frames: Matching 4 KB physical blocks inside physical RAM.



  3. The Page Table & MMU: A hardware component called the Memory Management Unit (MMU) uses a lookup table (the Page Table) to translate a program's virtual page address into a physical RAM frame address instantly.



+---------------------+     Translation     +---------------------+



| Virtual Address     |   (MMU Page Table)  | Physical RAM Frame  |



| Process A: Page 0   | ------------------> | RAM Frame 104       |



| Process B: Page 0   | ------------------> | RAM Frame 12        |



+---------------------+                     +---------------------+



Because of this mapping, Process A and Process B can both write to "Page 0" simultaneously without ever colliding in physical RAM.



5. Page Faults and Thrashing



What happens when your open applications require 18 GB of memory, but your computer only has 16 GB of physical RAM installed?




  1. Swapping to Disk: The OS moves inactive pages out of RAM and writes them to a hidden file on your SSD/HDD (known as the Swap File or Paging File).

  2. Page Fault: When you switch back to an inactive app, the CPU looks for its page in RAM, finds it missing, and triggers a Page Fault interrupt.

  3. Page Retrieval: The OS pauses the app, fetches the missing page from the SSD, loads it back into RAM, and updates the Page Table.



What is Thrashing?



If your memory demand vastly exceeds physical RAM, the OS spends nearly 100% of its time continually swapping pages back and forth between physical RAM and the disk drive. The system becomes unresponsive, disk activity spikes to 100%, and mouse cursors freeze. This phenomenon is called Thrashing.



Summary Matrix for Students



























OS Function



Primary Goal



Core Mechanism



Key Failure State



Process Scheduler



Fair CPU time distribution across active tasks.



Round Robin / Time Quantum / Context Switching



Starvation (tasks waiting indefinitely)



Memory Manager



Isolated, secure, and expanded memory access.



Virtual Memory / Paging / MMU Translation



Thrashing (excessive disk swapping)




 

Discussion (0)

Leave a Reply