Process
- The process is a program that's executing.
- When a program is loaded into the memory, it becomes a process.
- Each instance of the program is a different process.
Process Memory
Each process has process memory. Process Memory is divided as follows.
Stack:
It stores temporary data like function parameters, returns addresses, and local variables. The stack grows and shrink.
Heap:
It allocates memory, which may be processed during its run time.
Data:
It contains constants.
Text:
It includes the current activity, Contains Program Code.
Context Switching
Kernel switching from one process to another process is known as Context Switching.
Reasons for Context Switching
- A process with high priority arrives for execution.
- Running process requires I/O resources in the system and many more ...
Process State
When a process executes, it passes through different states. These stages may differ in different operating systems.
New:
The initial state when a process is first started/created.
Ready:
The process is waiting to be assigned to a processor.
Running:
The process is chosen by the CPU for execution and the instructions within the process are executed.
Waiting:
Process wait for a resource, such as waiting for user input, or waiting for a file to become available.
Terminated:
When a process finishes its execution, it comes in the termination state.
Process Control Block
A Process Control Block is a data structure maintained by the Operating System for every process. Context of a process represented in the PCB. The PCB is identified by an integer process identifier (PID).
CPU Scheduling
- Process of determining which process will own CPU for execution while another process is on hold.
- The aim of CPU scheduling is to make the system efficient, fast, and fair.
Whenever the CPU becomes idle, the OS must select one of the processes in the ready queue to be executed.
CPU Scheduling Algorithms
The selection process is carried out by the CPU scheduler using different algorithms they are
- First Come First Serve (FCFS)
- Shortest-Job-First (SJF) Scheduling
- Priority Scheduling
- Round Robin Scheduling and many more ...
CPU Scheduling Terminology
Arrival Time:
Time at which the process arrives in the ready queue.
Completion Time:
Time at which process completes its execution.
Burst Time:
The time required by a process for CPU execution.
Turnaround Time:
The total amount of time spent by a process in the system.
Waiting Time:
Amount of time spent by a process in the ready queue.
First Come First Serve
- A process that requests the CPU first gets the CPU allocated first.
- A process that arrived in the ready queue earlier will be executed earlier.
Example:
Process | Arrival Time | Burst Time |
---|---|---|
P1 | 0 | 21 |
P2 | 1 | 3 |
P3 | 2 | 6 |
P4 | 3 | 2 |
The process p1, p2, p3, and p4 are schedule with First Come First Serve are as follows.
So, the Completion time, Turnaround time, Waiting time of the process(p1, p2, p3 & p4) are as follows.
Process | Arrival Time | Burst Time | Completion Time | Turn Around Time | Waiting Time |
---|---|---|---|---|---|
P1 | 0 | 21 | 21 | 21 | 0 |
P2 | 1 | 3 | 24 | 23 | 20 |
P3 | 2 | 6 | 30 | 28 | 22 |
P4 | 3 | 2 | 32 | 29 | 27 |
Shortest Job First
Shortest Job First(SJF) scheduling works on the process with the shortest burst time or duration first.
Process | Arrival Time | Burst Time |
---|---|---|
P1 | 0 | 21 |
P2 | 1 | 3 |
P3 | 2 | 6 |
P4 | 0 | 2 |
The shortest job first scheduling for process p1, p2, p3, and p4 is as follows.
Priority Scheduling
Priority Scheduling Algorithm works on the process with the higher priority. Processes with the same priority are executed in an FCFS manner.
Process | Arrival Time | Burst Time | Priority |
---|---|---|---|
P1 | 0 | 21 | 2 |
P2 | 1 | 3 | 1 |
P3 | 2 | 6 | 4 |
P4 | 3 | 2 | 3 |
The processes(p1, p2, p3, and p4) scheduled based on Priority Scheduling are as follows.
Round Robin Scheduling
In Round Robin Scheduling a fixed time is allotted to each process called Time Slice for execution. Once a process is executed for the given time period then another process executes for the given time period.
Example:
Process | Arrival Time | Burst Time |
---|---|---|
P1 | 0 | 21 |
P2 | 1 | 3 |
P3 | 2 | 6 |
P4 | 3 | 2 |
Suppose the Time Slice is 5 units and the process p1, p2, p3, and p4 are scheduled in Round Robin Scheduling are as follows.
Inter Process Communication
IPC is a mechanism, where the OS allows various processes to communicate with each other.
Communication can be done through:
- Shared Memory
- Message passing
Shared Memory
- A particular region of memory is shared between the cooperating process.
- Exchanging information by reading and writing data to this shared region.
Message Passing
- Communication takes place by exchanging messages directly between the cooperating process.