Processes in Operating System

We offer you a brighter future with FREE online courses - Start Now!!

The program being executed by an operating system is a process. It takes place in a sequence and is the basic unit of work to be implemented in the system. A program during execution becomes a process and performs all the tasks for the user.

Sections of a Process in OS

A process has four sections. These sections are as follows:

1. Stack: This has temporary data like return address and local variables.

2. Heap: This is the memory allocated to a process dynamically, during its run time.

3. Text: This consists of the ongoing activity of a process that is represented by the value of the Program Counter and the contents of the processor’s registers.

4. Data: This has global and static variables.

Sections of a process in OS

Different times concerning a process in Operating System

1. Burst time: The time required for the execution of the process

2. Arrival time: The time at which the process enters the ready queue.

3. Turnaround time: The time taken by a process from entering the ready state for the first time till its exit time i.e., the difference between completion time and arrival time.

4. Waiting time: The time spent by the process in ready state i.e., the difference between turnaround time and burst time.

5. Exit time: The time at which the process completes execution and exits the system.

6. Response time: The time taken by a process, to be allocated to the CPU, for the first time after entering ready queue i.e., the difference between the time a process first gets CPU and the arrival time

7. Throughput: This is a way to find the efficiency of a processor. It is the number of processes executed by the CPU in a given amount of time.

Program

Program is a part of a code. It can be of any length from a single line to millions of lines. A computer programmer or coder is responsible for writing a program. It is a set of instructions written to perform specific tasks for the user. Following is a simple example of a program in the C programming language:

#include <stdio.h>

int main() {
   printf("DataFlair \n");
   return 0;
}

We can say that a process is a dynamic instance of a program. The secondary storage stores a program. This program converts into a process during execution. Software is a collection of computer programs, libraries, and related data.

Process vs Program in OS

The following table shows the difference between a process and a program.

ProcessProgram
An instance of a program being executed.A collection of instructions written to perform a specific task for the user. 
Short lifetimeLong lifetime
Requires resources such as memory, CPU, I/O devices, etc…Stored in hard-disk and doesn’t requires any resources
Has a dynamic instance of code and data Has static code and data.
Running instance of code Executable code

Process Life Cycle in OS

During execution, a process has to go through multiple states. Though these states and their names differ in different operating systems, the following are the common states of the process life cycle:

1. Start: The initial state of a process when it is first created.

2. Ready: In this state, the process is ready to be assigned to a processor and waits for the OS to allocate the processor to it. A process can come into this state multiple times especially when the scheduler assigns the CPU to another process.

3. Running: After being assigned to a processor, the process enters into the running state and the processor executes its instructions.

4. Waiting: If another process occupies the resource required by the running process, the running process moves into a waiting state.

5. Terminated or Exit: A process moves to this state when an OS terminates it, or after it finishes execution and waits to be removed from the main memory.

Process Control Block (PCB) in OS

A data structure retained by the OS for each process is known as a process control block. Each PCB has its own integer process ID (PID) which is the identity of the PCB. PCB is a collection of all the information regarding a process like the state of the process, location of a process, etc. The lifetime of a PCB is as long as that of a process i.e., till the OS terminates a process.

Following is the information that PCB keeps a track of:

1. Process State: This is the current state of the process. It can be any state then, ready, running, waiting, or any else.

2. Process privileges: This allows/disallows access to system resources.

3. Process ID: This is the unique identification of a process like aadhar card for us.

4. Pointer: It is a pointer to the parent process.

5. Program Counter: This points to the address of the next instruction that is to be executed for a process.

6. CPU registers: This is where a process is stored before execution or entering the running state.

7. CPU Scheduling Information: Stores process priority and other scheduling information necessary for scheduling a process.

8. Memory management information: This contains page table information, memory limits, and segment table based on the memory used by the operating system.

9. Accounting information: Stores information regarding the amount of times a processor is used for process execution, time limits, execution ID, etc.

10. I/O status information: The list of I/O devices allocated to the process is stored here.

Process Control Block (PCB) in OS

CPU-Bound vs I/O-Bound Processes

The process of CPU-bound needs more CPU time i.e., it spends more time in the running state. Whereas the process of I/O-bound needs more I/O time and less CPU time i.e., it spends more time in the waiting state.

Process Scheduling in OS

A process is the basis of computation. A process is a lot more than a program code. It is a program in execution. A process has four sections, namely, text, data, heap, and stack. We will discuss process scheduling and its types in detail in the next segment.

Summary

A process is an instance of a running program. There are four sections of a process stack, heap, text, and data. There are five states in a process, namely, new, ready, running, waiting, and termination. Every process has its own PCB that keeps track of all the information related to a process like a process ID, process state, pointer, priority, program counter, CPU register, I/O information, accounting information, and much more.

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *