What is a process?
What resources does a running program have?
The articles written on this blog were created with the goal of teaching. Also, the information in the article may be incorrect, so please be careful.
An executable file is code and data stored on disk. The state in which the operating system loads this executable file into memory and attaches the resources necessary for execution is called a process.
In other words, a program is a file, and a process is an instance of a running program.
What a process has
A process contains more than just code.
- Independent virtual address space
- Executable code and global data
- Dynamically allocated heap
- Stack used by thread
- Open file and socket information
- Security permissions and process identity
high address
┌──────────────┐
│ Stack │ Thread’s function calls and local variables
├──────────────┤
│ │
│ Heap │ Dynamic allocation such as new, malloc, etc.
├──────────────┤
│ Data / BSS │ Global variables, static variables
├──────────────┤
│ Code │ Command to execute
└──────────────┘
low address
The actual arrangement and detailed areas may vary depending on the operating system and executable file type, but the flow of having memory areas for different purposes is the same.
Processes are isolated from each other
Even if process B takes the pointer used by process A, it cannot access the same data. This is because each process has its own virtual address space, and the kernel connects it to real memory through page tables.
This isolation means that if one browser goes wrong, it doesn't immediately destroy the memory of other programs.
Processes need a way to communicate with each other
Since the memory is separate, IPC (Inter-Process Communication) must be used to exchange data between processes.
- Pipe
- Shared Memory
- Socket
- Message Queue
Shared memory is fast, but requires synchronization when accessed simultaneously. Socket and message methods have clear boundaries, but may incur data copy and communication costs.
A process is not simply a piece of executing code. The operating system is closer to a resource container that manages memory, files, permissions, and one or more threads.