Process is a program in execution. Process is an active entity, while a program is a passive entity. This means that a program can be considered as a bunch of code, or sequence of instructions, whereas a process is any such program that is currently active. A process can have several states, and is completely described in a PCB, or Process Control Block. There are three major topics we will be covering in this post, they are - the four sections of a process, life cycle of process, and process control block.
Sections of a Process
A process is divided into four major sections:
- Code Section: Code section consists of the code, or instructions of the process. Basically, it is indicatged by the program counter and instruction registers which hold the current and to-be executed instructions.
- Data Section: This section contains static and global variables, which are initialized before the program is executed.
- Heap Section: This consists of dynamically allocated memory in the process, using free, alloc, malloc etc. calls.
- Stack Section: This contains local variables of process and other temporary data, such as address of next instruction during function calls. Contents of this section are automatically destroyed in the order of the stack, as and when they reach the end of their scope.
Life Cycle of a Process
|
States of a Process |
- New: The process has just been created/being initialised.
- Ready: The process is now waiting to be allocated to processor.
- Running: The process has been allocated a processor and is now being executed.
- Waiting: The process is waiting for another resource to become available, such as an I/O request, or a file handling (secondary memory) request.
- Terminated: The process has either been aborted or it has successfully completed execution. After this the process is removed from the main memory.
Process Control Block
A process control block is a data structure that maintains all information pertaining to a process. The lifetime of a PCB equals that of its corresponding process. It includes:
- Process ID (pid in unix) : The ID of the process as given by the operating system. It may also additionally provide the parent process ID (ppid in unix).
- Process State: State of the process as described in the previous section - ready, running etc.
- CPU registers: The Instruction Register (IR) contains the address of the current instruction to be decoded.
- Program Counter: The program counter contains the address of the next instruction to be executed.
- I/O Status: This contains a list of devices allocated / to-be-allocated, and other resources, like open / closed file descriptors.
- Memory Information, CPU Scheduling Information, Priority, other pointers etc.