Operating System: Processes
What is a process?
A process is defined as an entity that represents the basic unit of work to be executed in the system.
In other words, when a program is loaded in the memory, it is known as a process. It can be further divided into four parts: stack, heap, data, and text.
Stack: The stack contains temporary data such as the address to return to when the process completes, the input arguments to the function, and space for local variables.
Heap: It is an area of pre-reserved computer main memory that a process can use to store data in some variable amount that will be unknown until the program is running.
Data: Where the static and global variables are stored.
Text: The contents of the processor’s registers and the current activity represented by the value of the Program counter are stored here.
Primary process states
A process passes through different states when it is executed, these states may vary in different operating systems.
The following are the primary process states:
- Created
When a process is initially created it is put in the “new” or “created” state.
- Ready
A process that has been loaded in the main memory and is waiting to be executed on a CPU is said to be in the “ready” or “waiting” state.
- Running
A process moves into a running state when it is chosen for execution.
There are two modes in the running state:
- Kernel mode: In this mode, the processes can access both kernel and user addresses.
- User mode: In this mode, the processes can access only their data and instructions.
The system is in user mode whenever the computer system has to execute on behalf of a user application.
When a user application requests a service from the operating system, the system switches to kernel mode to fulfill the request.
- Blocked
A process moves to a blocked state when it cannot continue without any external changes.
- Terminated
When a process has completed its execution or has been killed it is moved to a “terminated” state.
Process Control Block (PCB)
A Process Control Block is a data structure maintained by the Operating System for every process.
A PCB stores the following information:
- Process state
- Process privileges
- Pointer
- Process ID
- Program counter
- CPU registers
- I\O status information
- Accounting information
- Memory management information.
Reference:
Processes of Operating system.