Process Concept

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Objective

A process and its attributes


Difference between program and process
States of a process
Process Memory
Process

A process is a program in execution.


A process is an 'active' entity as opposed to program which is considered
to be a 'passive' entity. Attributes held by process include hardware state,
memory, CPU etc.

How to Make Honey-Lemon-Ginger


Tea
1.In a pan heat 3 cups of water.
2.Before it begins to boil add ginger.
3.Just as it starts to boil add the tea
leaves, lemon juice and honey.
4.Strain it into a cup and enjoy!
Program Vs Process
Program contains a set of instructions Process is an instance of an
designed to complete a specific task. executing program.

Program is a passive entity as it Process is a active entity as it is


resides in the secondary memory. created during execution and loaded
into the main memory.

Program exists at a single place and Process exists for a limited span of
continues to exist until it is deleted. time as it gets terminated after the
completion of task.

Program is a static entity. Process is a dynamic entity.

Program does not have any resource Process has a high resource
requirement, it only requires memory requirement, it needs resources like
space for storing the instructions. CPU, memory address, I/O during its
lifetime.

Program does not have any control Process has its own control block
block. called Process Control Block.
Process
A process is an instance of a program in execution.
For example, when we write a program in C or C++ and compile it, the
compiler creates binary code. The original code and binary code are
both programs. When we actually run the binary code, it becomes a
process.
Contd…
A single program can create many processes when run multiple times; for
example, when we open a .exe or binary file multiple times, multiple
instances begin (multiple processes are created).

• A program is a passive entity, such as a file containing a list of instructions


stored on disk (often called an executable file ). In contrast, a process is an
active entity, with a program counter specifying the next instruction to
execute and a set of associated resources.
Process in Memory
Text Section: A Process, sometimes known as the Text
Section, also includes the current activity represented
by the value of the Program Counter.
Data Section: Contains the global variable.
Stack: The stack contains the temporary data, such as
function parameters, returns addresses, and local
variables.
Heap Section: Dynamically allocated memory to
process during its run time.
*Note:-The stack and heap sections shrink and grow
dynamically during program execution. Even though,
they grow toward one another, the operating system
must ensure they do not overlap one another.
Attributes or Characteristics of Process
A Process Control Block (PCB) of each process, encloses all
the information about the process. It is also known as the
task control block. It is a data structure, which contains the
following:
Process ID: When a process is created, A unique identifier
(ID) assigned by the operating system to each process.
Program Counter: The counter indicates the address of the
next instruction to be executed for this process.
Process State: The state may be new, ready, running,
waiting, halted.
Priority: Every process has its own priority. The process
with the highest priority among the processes gets the CPU
first.
Contd…
General Purpose Registers: Every process has its own set of registers which
are used to hold the data which is generated during the execution of the
process.
List of open files : During the Execution, Every process uses some files which
need to be present in the main memory. OS also maintains a list of open files
in the PCB.
List of open devices : OS also maintain the list of all open devices which are
used during the execution of the process.
Memory-management information: This information may include such items
as the value of the base and limit registers and the page tables, or the
segment tables, depending on the memory system used by the operating
system.
Accounting information: This information includes the amount of CPU and
real time used, time limits, account numbers, job or process numbers, and so
on.
*Note:- All of the above attributes of a process are also known as the context of
the process.
State of Process
The process, from its creation to completion, passes through various
states.
Contd…
New: The process is being created. A program which is going to be
picked up by the OS into the main memory is called a new process.
Ready: After creation process moves to Ready state. The processes
which are ready for the execution and reside in the main memory are
called ready state processes. The process is waiting to be assigned to a
processor.
Run: Currently running process in CPU. One of the processes from the
ready state will be chosen by the OS depending upon the scheduling
algorithm. For uni-processor system, the number of running processes
for a particular time will always be one. Whereas for multiprocessor
system, having n processors can have n processes running
simultaneously.
Contd…
Termination: The process has finished execution. All the context of the
process (Process Control Block) will also be deleted the process will be
terminated by the Operating system.
Wait or Block: When a process waits for a certain resource (I/O device)
to be assigned or for the input from the user then the OS move this
process to the block or wait state and assigns the CPU to the other
processes.
Suspend ready: A process in the ready state, which is moved to
secondary memory from the main memory due to lack of the resources
(mainly primary memory) is called in the suspend ready state.
If the main memory is full and a higher priority process comes for the execution
then the OS have to make the room for the process in the main memory by
throwing the lower priority process out into the secondary memory. The
suspend ready processes remain in the secondary memory until the main
memory gets available.
Contd…
Suspend wait: Instead of removing the process from the ready queue,
it's better to remove the blocked process which is waiting for some
resources in the main memory. Since it is already waiting for some
resource to get available hence it is better if it waits in the secondary
memory and make room for the higher priority process. These processes
complete their execution once the main memory gets available and their
wait is finished.
Context Switch
The process of saving the context of one process and loading the
context of another process is known as Context Switching. In simple
terms, it is like loading and unloading the process from the running
state to the ready state.
Context switching happen
When a high-priority process comes to a ready state (i.e. with higher priority
than the running process)
An Interrupt occurs
User and kernel-mode switch (It is not necessary though)
Preemptive CPU scheduling used.
Contd…
Contd…
Firstly, the context of the process P1, i.e., the process present in the
running state will be saved in the Process Control Block (PCB) of process
P1, i.e., PCB1.
Now, move PCB1 to waiting queue.
From the ready state, select the new process that is to be executed,
i.e., the process P2.
Now, update the Process Control Block (PCB) of process P2, i.e., PCB2
by setting the process state to running. If the process P2 was earlier
executed by the CPU, then you can get the position of last executed
instruction so that you can resume the execution of P2.
Similarly, if you want to execute the process P1 again, then you have to
follow the same steps as mentioned above (from step 1 to 4).
Operations on Process
Process Creation: Once the process is created, it will be ready and come
into the ready queue (main memory) and will be ready for the
execution.
A process may create several new processes. the creating process is
called a parent process, and the new processes are called the children
of that process. Each of these new processes may in turn create other
processes, forming a tree of processes.
When a process creates a new process, two possibilities for execution
exist:
 The parent continues to execute concurrently with its children.
 The parent waits until some or all of its children have terminated.
There are also two address-space possibilities for the new process:
The child process is a duplicate of the parent process (it has the same program
and data as the parent).
The child process has a new program loaded into it.
Contd…
Example: Unix Operating system
A new process is created by the fork() system call. The new process
consists of a copy of the address space of the original process. This
mechanism allows the parent process to communicate easily with its
child process.
After a fork() system call, one of the two processes typically uses the
exec() system call to replace the process’s memory space with a new
program. The exec() system call loads a binary file into memory and
starts its execution.
The parent process can issue a wait() system call to move itself off the
ready queue until the termination of the child.
When the child process completes (by invoking exit() system call), the
parent process resumes from the call to wait(), where it completes
using the exit() system call.
Fork()

Let n= number of fork() system call


Total number of process= 2^n
Total number of child process= 2^n – 1
For example n=2, number of process= 2^2 = 4 and number of child process= 2^2 -1 = 3
Contd…

System Calls
Process Termination
A process terminates when it finishes executing its final statement and
asks the operating system to delete it by using the exit() system call.
A parent may terminate the execution of one of its children for a variety
of reasons, such as these:
 The child has exceeded its usage of some of the resources that it has been
allocated. (To determine whether this has occurred, the parent must have a
mechanism to inspect the state of its children.)
The task assigned to the child is no longer required.
The parent is exiting, and the operating system does not allow a child to
continue if its parent terminates.
A process that has terminated, but whose parent has not yet called
wait(), is known as a zombie process.
If a parent did not invoke wait() and instead terminated, thereby leaving
its child processes as orphans.
Process Pre-emption
An interrupt mechanism suspends the process executing currently and
give CPU to another process. Preemption makes sure that all processes
get some CPU time for execution.
Process Blocking
The process is blocked if it is waiting for some event to occur. This
event may be I/O as the I/O events are executed in the main memory
and don't require the processor. After the event is complete, the
process again goes to the ready state.
Types of Process
If the process is intensive in terms of CPU operations then it is called
CPU bound process. Similarly, If the process is intensive in terms of I/O
operations then it is called IO bound process.

A CPU-bound process requires more CPU time or spends more time in


the running state.
An I/O-bound process requires more I/O time and less CPU time. An
I/O-bound process spends more time in the waiting state.
Thank You

You might also like