Winter Semester 2026–27 · VIT-AP · BACSE106 · Operating Systems · Dr. Krithika L.B

Session 2.1: Process concept and process scheduling

What a process is, how it is laid out in memory, the five states it moves through, the PCB that represents it, and how the kernel switches between processes.

Module 2 2 hours Theory CO2
← Before
1.4 Interrupts & booting
End of Module 1
You are here
2.1 Process concept and process scheduling
Module 2 · Process, Scheduling, Threads and Deadlocks
Next →
2.2 Operations on processes
fork, exec, wait, exit

Learning objectives

By the end of this session you should be able to:

  • Distinguish a program from a process and draw the memory layout of a process.
  • Trace a process through the five-state model and name the event behind each transition.
  • List the contents of a Process Control Block and explain why each field is needed.
  • Describe the steps of a context switch and why it is overhead.
  • Explain the ready and device queues and the roles of the long-, short- and medium-term schedulers.

Lecture notes

1. Program vs process

Module 1 ended with systemd starting as PID 1. From that moment, everything the kernel manages is a process. A program is a passive file on disk (an executable such as /usr/bin/gcc). A process is a program in execution: it has a program counter, registers, open files, memory and a state. One program can give rise to many processes — ten students running gcc on the same server create ten processes from one file.

Definition

A process is the unit of work in a modern OS: a program in execution together with its current activity — program counter, CPU registers, stack, data, heap and the resources the kernel has given it.

2. A process in memory

Each process gets its own address space, laid out in four regions:

max address
Stack — function frames, local variables, return addresses (grows ↓)
↓ free space ↑
Heap — malloc() / new memory (grows ↑)
Data — global and static variables
Text — the machine code of the program
0
layout.c — where does each variable live?
#include <stdio.h>
#include <stdlib.h>

int counter = 0;                 /* data section            */

int main(void)                   /* main's code: text       */
{
    int local = 5;               /* stack                   */
    int *p = malloc(sizeof(int)); /* p on stack, *p on heap */
    printf("text  %p\ndata  %p\nheap  %p\nstack %p\n",
           (void *)main, (void *)&counter, (void *)p, (void *)&local);
    free(p);
    return 0;
}

Run it and you will see the addresses increase from text → data → heap, with the stack far above — exactly the picture.

3. Process states

As a process executes it changes state. The classic five-state model:

New
Ready
Running
Waiting
Terminated

New — the process is being created: the kernel allocates a PCB and an address space and loads the program.

New
Ready
Running
Waiting
Terminated

New → Ready (admitted). The process has everything it needs except the CPU. It waits in the ready queue.

New
Ready
Running
Waiting
Terminated

Ready → Running (scheduler dispatch). The CPU scheduler picks it; the dispatcher loads its registers. On one core only one process is Running at a time.

New
Ready
Running
Waiting
Terminated

Running → Ready (interrupt). The timer interrupt fires (time slice over) or a higher-priority process arrives. It goes back to the ready queue — it can still run.

New
Ready
Running
Waiting
Terminated

Running → Waiting (I/O or event wait). The process asked for a disk read or called wait(); it cannot use the CPU until the event happens.

New
Ready
Running
Waiting
Terminated

Waiting → Ready (I/O or event completion). The device interrupt (Session 1.4) wakes it. Note: it goes to Ready, not straight back to Running.

New
Ready
Running
Waiting
Terminated

Running → Terminated (exit). The process calls exit() or is killed. Its resources are freed; the PCB stays until the parent collects the exit status.

A common exam trap

There is no Waiting → Running transition and no Ready → Waiting transition. A process can only start waiting while it is running (it must execute the instruction that requests I/O), and when the wait ends it must queue for the CPU again.

4. Process Control Block (PCB)

The kernel represents each process by a PCB (in Linux, struct task_struct). It holds everything needed to stop the process and later resume it exactly where it left off:

Identification

Process ID (PID), parent PID, user and group IDs.

Process state

New, ready, running, waiting, terminated.

CPU context

Program counter and all CPU registers, saved on every switch.

Scheduling info

Priority, pointers into scheduling queues, CPU time used.

Memory-management info

Base/limit registers or page-table pointer (Module 4).

Accounting & I/O status

CPU time, time limits, list of open files and allocated devices.

5. Context switch

Switching the CPU from one process to another requires saving the state of the old process into its PCB and loading the saved state of the new one — a context switch.

Process P0 is executing in user mode. Its registers live in the CPU.

A timer interrupt or system call traps into the kernel (Session 1.4).

The kernel saves P0's program counter, registers and state into PCB0.

The scheduler chooses the next process, P1, from the ready queue.

The kernel reloads P1's registers from PCB1, switches the memory map, and returns to user mode.

P1 continues exactly where it stopped last time. P0 sits in a queue until it is chosen again.

Context-switch time is pure overhead

No useful work is done during the switch — typically a few microseconds. It depends on memory speed, the number of registers, and whether caches/TLB must be flushed. This cost is why time slices cannot be made arbitrarily small (Session 2.5).

6. Process scheduling: queues and schedulers

The goal of multiprogramming is to keep the CPU busy; the goal of time-sharing is to switch often enough for users to interact. The kernel keeps processes in queues:

  • Job queue — all processes in the system.
  • Ready queue — processes in memory, ready and waiting for the CPU (a linked list of PCBs).
  • Device (wait) queues — processes waiting for a particular I/O device or event.
Ready queue→ CPU→ I/O request → I/O queue → back to ready time slice expired → back to ready fork child → back to ready wait for interrupt → back to ready

A queueing diagram: a process circulates between queues until it terminates.

SchedulerDecidesRunsControls
Long-term (job scheduler)Which jobs are admitted into memorySeconds/minutes apartDegree of multiprogramming; aims for a good mix of I/O-bound and CPU-bound jobs
Short-term (CPU scheduler)Which ready process gets the CPU nextEvery few milliseconds — must be fastCPU allocation (Sessions 2.4–2.5)
Medium-termWhich process to swap out of / back into memoryWhen memory is over-committedReduces the degree of multiprogramming temporarily (swapping, Module 4)

An I/O-bound process spends more time doing I/O than computing (many short CPU bursts — an editor). A CPU-bound process does long computations (a video encoder). A good mix keeps both the CPU and the devices busy.

VideoBytes

Process concept, states and the PCB

Video coming soon

Process concept, states and the PCB

Recorded by Dr. Krithika L.B. Slot m2-process-states

Context switch and scheduling queues

Video coming soon

Context switch and scheduling queues

Recorded by Dr. Krithika L.B. Slot m2-context-switch

Interactive lessons

Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.

Lab connection

Check your understanding

Answer each question in your own words first, then reveal the model answer.

Revealed 0
Why can't a process move directly from Waiting to Running?

When the event completes, the scheduler may already be running another process. The woken process must join the ready queue and wait to be dispatched — only the short-term scheduler moves processes to Running.

What is stored in a PCB and why is the program counter essential?

PID, state, PC and registers, scheduling info, memory info, accounting and open files. The PC tells the CPU which instruction to execute next when the process resumes; without it the process could not continue where it stopped.

Distinguish the short-term and long-term schedulers.

The short-term scheduler picks the next process for the CPU many times a second; the long-term scheduler decides which jobs enter memory (controlling the degree of multiprogramming) and runs rarely.

Why should time slices not be made extremely small?

Every switch costs context-switch time with no useful work. With a tiny slice, a large fraction of CPU time is wasted on switching.

In layout.c, where do counter, local, p and *p live?

counter → data; local → stack; p (the pointer variable) → stack; *p (the int it points to) → heap.

Key takeaways

  • A process is a program in execution with its own text, data, heap and stack.
  • Five states: new, ready, running, waiting, terminated — each transition has a specific cause.
  • The PCB holds everything needed to stop and resume a process; a context switch saves one PCB and loads another.
  • Queues hold PCBs; long-, short- and medium-term schedulers decide admission, CPU allocation and swapping.

Where this leads

We know what a process is. But where do processes come from, and how do they end? Next: fork(), exec(), wait() and exit().

Continue to 2.2 — Operations on processes →