DEV Community

Shariful Islam Sourav
Shariful Islam Sourav

Posted on

Address Space and Process Control Block(PCB)

 π€πππ«πžπ¬π¬ π’π©πšπœπž: Every process running on our systems has memory allocated for its address space. Which includes:

|| 𝘚𝘡𝘒𝘀𝘬 β†’ 𝘎𝘒𝘱 β†’ 𝘏𝘦𝘒𝘱 β†’ π˜‹π˜’π˜΅π˜’ β†’ π˜›π˜¦π˜Ήπ˜΅||

β€’ Stack: Contains function calls, return addresses, local variables etc.
β€’ Gap: That's just the empty space kept for the dynamic memory to grow.
β€’ Heap: Used for dynamic memory allocation like malloc(), calloc().
β€’ Data: For const, global and static variables.
β€’ Text: The program code or program instructions. (Usually read-only)

-These address spaces are separate for each process and they cannot access each others. OS manages the whole thing, if something wrong happens OS throws Segmentation Fault.
-Address space is virtual. Which is mapped to physical memory by OS.

𝐏𝐂𝐁: In simple words, a Process Control Block is a data structure used by OS to manage processes. It’s like an ID Card for processes.
Which includes:

β€’ Process ID (PID): Unique id for the process.
β€’ Process State: New, Ready, Running, Waiting, Terminated these are the states.
β€’ CPU Registers: Program Counter(PC) and other registers.
β€’ Scheduling Information: Priority and queue position.
β€’ Memory Information: Pointers to address space and memory limits.
β€’ I/O Status Information: Open files, devices used.

-PCB is stored inside the Kernel Space inside the process table.
-OS uses PCB to manage processes, perform context switching and track process execution

Simple analogy is PCB contains everything the OS needs to identify and manage a process.

Top comments (0)