What are Processes and Threads?
Processes
When you open applications on your computer (word processor, music player), these become different processes. Applications are first loaded from the hard disk to RAM, where they become active processes.
Threads
Multiple processes can have multiple threads running inside them:
- Word processor: One thread handles user input, another performs auto-formatting
- Music player: One thread plays music, another manages song shuffling
Most modern applications are multi-threaded because multi-threading provides better CPU utilization and takes advantage of multi-core processors.
Process Memory Structure
A typical process in memory contains:
- Code segment: The program instructions
- Data segment: Global and static variables
- Heap: Dynamic memory allocation
- Stack: Function call management
Single-threaded Process
- Has only one stack for managing function calls
- Called a "single thread of execution"
- Main function calls other functions sequentially
Multi-threaded Process