Monday 24 August 2020

Concept of a Process in Operating System (OS):

Concept of a Process in OS: 

When an OS runs a program, it is loaded into memory and the control is transferred to the first instruction of that program. After that, the program starts to run. A process can be defined as a program in execution. It is used as a unit of work for a processor. Every process has a program counter (PC), a stack, data section, etc. Furthermore, there can be multiple processes associated with one program. As such, a process is more than a program.

 

A process consists of components like:

Object program - object program i.e. code to be executed.

Data - data is used for executing the program.

Resources - while executing the program, it may require some resources.

Status - to verify the status of process execution.

 

The common attributes of a process consists of the hardware state, memory, CPU and the progress (execution status) of that process. Another important consideration is that a program is called a passive entity, while a process is an active entity. A program becomes process when, executable file is loaded into memory.

 

A process is more than a program code. This program code is generally called as the text section. A data section contains global variables and the heap contains memory that is dynamically allocated during runtime. Whereas, a stack usually has temporary data like temporary variables, local variables, function or subroutine parameters, return addresses, etc. In cases, a same program may have two or more processes that are associated with it. But, they are not considered as separate execution sequences. A program can create multiple processes. For ex: a web browser application.


 Process vs. Programs:


Process vs. Program

Process States:

Whenever a process executes, there occurs change in its state. Usually, a process state is determined by the current activity of the process. Each process may be in one of the following states:

 

1.    New: the process has just been created.

2.    Running: the process is currently being executed.  A running process has all the resources that are needed for its execution, including the processor.

3.    Waiting: the process is waiting for some event to occur. A running process may become suspended by invoking an IO routine.

4.    Ready: the process is waiting to be assigned to a processor allocated to them by OS so that it can run.

5.    Terminate: the process has finished its execution and no longer requires CPU.

 

Whenever a process changes its state, an OS updates the process PCB (Process Control Block) in the list that corresponds to its new state. Only one process can be running in any processor at any time. However, there can be many processes in ready and waiting states.  Processes that are in ready state are loaded into a ready queue. A ready queue is a one type of data structure used by an OS to store the processes.


Process states


Transitions of Process States:

NewReady:  an OS creates a process and prepares it to be executed. After that OS moves the process into the ready queue.


ReadyRunning: when it is a time to select a process to run, OS selects one of the jobs from the ready queue and move the process from ready state to running state.


RunningTerminated: when a process completes its execution, then the OS terminates that process from running state. An OS may terminate a process because of some other reasons too. Some possible reasons are time limit exceeded, memory unavailable, access violation, protection error, IO failure, etc.


RunningReady: an OS shifts a running process to a ready state when the time slot of the processor expires or it receives an interrupt signal.  Consider an example, suppose process P1 is being executed by processor. Meanwhile, a process P2 generates an interrupt signal to processor. In this case, the processor first compares the priorities of processes P1 and P2.  If P1>P2, then the processor continues the process P1. Otherwise, processor switches to process P2 and the process P1 is moved to the ready state.


RunningWaiting: if a process requires some event to occur for its completion or if there is an IO device requirement, in such cases a process is put into waiting state. Whenever, an OS cannot not provide IO or that event immediately, a process is moved to waiting state by the OS.


WaitingReady:  a process which is in the blocked state is moved to ready state when the event for which it has been waiting occurs.  For ex: a process is in running state, it need an IO device, then the process moved to blocked or waiting state. Now, when the IO device is provided by OS, the process is moved to ready state from waiting or blocked state.



No comments:

Post a Comment