0% found this document useful (0 votes)
3 views

Process in Operating System(Unit 2)

A process is an executing program that includes various attributes like memory and CPU state, while a program is a static collection of instructions. Processes can exist in multiple states such as NEW, READY, RUNNING, WAITING, and TERMINATED, and are managed through a Process Control Block. Process scheduling is crucial for efficient CPU utilization and can be categorized into long-term, short-term, and medium-term scheduling, with context switching being a key operation in managing processes.

Uploaded by

nijaniarul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Process in Operating System(Unit 2)

A process is an executing program that includes various attributes like memory and CPU state, while a program is a static collection of instructions. Processes can exist in multiple states such as NEW, READY, RUNNING, WAITING, and TERMINATED, and are managed through a Process Control Block. Process scheduling is crucial for efficient CPU utilization and can be categorized into long-term, short-term, and medium-term scheduling, with context switching being a key operation in managing processes.

Uploaded by

nijaniarul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Process in Operating System

A process is a program in execution which then forms the basis of all computation. The
process is not as same as program code but a lot more than it. A process is an 'active' entity as
opposed to the program which is considered to be a 'passive' entity. Attributes held by the
process include hardware state, memory, CPU, etc.

Process memory is divided into four sections for efficient working :

 The Text section is made up of the compiled program code, read in from non-volatile
storage when the program is launched.
 The Data section is made up of the global and static variables, allocated and
initialized prior to executing the main.
 The Heap is used for the dynamic memory allocation and is managed via calls to
new, delete, malloc, free, etc.
 The Stack is used for local variables. Space on the stack is reserved for local variables
when they are declared.

The different Process States

Processes in the operating system can be in any of the following states:

 NEW- The process is being created.


 READY- The process is waiting to be assigned to a processor.
 RUNNING- Instructions are being executed.
 WAITING- The process is waiting for some event to occur(such as an I/O completion
or reception of a signal).
 TERMINATED- The process has finished execution.

Process Control Block

There is a Process Control Block for each process, enclosing 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 State: It can be running, waiting, etc.


 Process ID and the parent process ID.
 CPU registers and Program Counter. Program Counter holds the address of the next
instruction to be executed for that process.
 CPU Scheduling information: Such as priority information and pointers to scheduling
queues.
 Memory Management information: For example, page tables or segment tables.
 Accounting information: The User and kernel CPU time consumed, account
numbers, limits, etc.
 I/O Status information: Devices allocated, open file tables, etc.

Process vs Program

Let us take a look at the differences between Process and Program:

Process Program

The process is basically an A Program is basically a collection of


instance of the computer program instructions that mainly performs a specific
that is being executed. task when executed by the computer.

A process has a shorter lifetime. A Program has a longer lifetime.

A Process requires resources such


A Program is stored by hard-disk and does not
as memory, CPU, Input-Output
require any resources.
devices.

A process has a dynamic instance


A Program has static code and static data.
of code and data

Basically, a process is the running On the other hand, the program is the
instance of the code. executable code.
Process Scheduling

When there are two or more runnable processes then it is decided by the Operating system
which one to run first then it is referred to as Process Scheduling.

A scheduler is used to make decisions by using some scheduling algorithm.

Given below are the properties of a Good Scheduling Algorithm:

 Response time should be minimum for the users.


 The number of jobs processed per hour should be maximum i.e Good scheduling
algorithm should give maximum throughput.
 The utilization of the CPU should be 100%.
 Each process should get a fair share of the CPU.

What is Process Scheduling?

The act of determining which process is in the ready state, and should be moved to the
running state is known as Process Scheduling.

The prime aim of the process scheduling system is to keep the CPU busy all the time and to
deliver minimum response time for all programs. For achieving this, the scheduler must apply
appropriate rules for swapping processes IN and OUT of CPU.

Scheduling fell into one of the two general categories:

 Non Pre-emptive Scheduling: When the currently executing process gives up the
CPU voluntarily.
 Pre-emptive Scheduling: When the operating system decides to favour another
process, pre-empting the currently executing process.

What are Scheduling Queues?

 All processes, upon entering into the system, are stored in the Job Queue.
 Processes in the Ready state are placed in the Ready Queue.
 Processes waiting for a device to become available are placed in Device Queues.
There are unique device queues available for each I/O device.

A new process is initially put in the Ready queue. It waits in the ready queue until it is
selected for execution(or dispatched). Once the process is assigned to the CPU and is
executing, one of the following several events can occur:

 The process could issue an I/O request, and then be placed in the I/O queue.
 The process could create a new subprocess and wait for its termination.
 The process could be removed forcibly from the CPU, as a result of an interrupt, and
be put back in the ready queue.
In the first two cases, the process eventually switches from the waiting state to the ready
state, and is then put back in the ready queue. A process continues this cycle until it
terminates, at which time it is removed from all queues and has its PCB and resources
deallocated.

Types of Schedulers

There are three types of schedulers available:

1. Long Term Scheduler


2. Short Term Scheduler
3. Medium Term Scheduler

Let's discuss about all the different types of Schedulers in detail:

Long Term Scheduler

Long term scheduler runs less frequently. Long Term Schedulers decide which program must
get into the job queue. From the job queue, the Job Processor, selects processes and loads
them into the memory for execution. Primary aim of the Job Scheduler is to maintain a good
degree of Multiprogramming. An optimal degree of Multiprogramming means the average
rate of process creation is equal to the average departure rate of processes from the execution
memory.

Short Term Scheduler

This is also known as CPU Scheduler and runs very frequently. The primary aim of this
scheduler is to enhance CPU performance and increase process execution rate.

Medium Term Scheduler

This scheduler removes the processes from memory (and from active contention for the
CPU), and thus reduces the degree of multiprogramming. At some later time, the process can
be reintroduced into memory and its execution van be continued where it left off. This
scheme is called swapping. The process is swapped out, and is later swapped in, by the
medium term scheduler.

Swapping may be necessary to improve the process mix, or because a change in memory
requirements has overcommitted available memory, requiring memory to be freed up.

What is Context Switch?

1. Switching the CPU to another process requires saving the state of the old process and
loading the saved state for the new process. This task is known as a Context Switch.
2. The context of a process is represented in the Process Control Block(PCB) of a
process; it includes the value of the CPU registers, the process state and memory-
management information.
3. Context switch time is pure overhead, because the system does no useful work
while switching. Its speed varies from machine to machine, depending on the
memory speed, the number of registers that must be copied, and the existence of
special instructions(such as a single instruction to load or store all registers). Typical
speeds range from 1 to 1000 microseconds.

Operations on Process

Below we have discussed the two major operation Process Creation and Process
Termination.

Process Creation

Through appropriate system calls, such as fork or spawn, processes may create other
processes. The process which creates other process, is termed the parent of the other process,
while the created sub-process is termed its child.

Each process is given an integer identifier, termed as process identifier, or PID. The parent
PID (PPID) is also stored for each process.

There are two options for the parent process after creating the child :

 Wait for the child process to terminate before proceeding. Parent process makes a
wait() system call, for either a specific child process or for any particular child
process, which causes the parent process to block until the wait() returns.
 Run concurrently with the child, continuing to process without waiting.

There are also two possibilities in terms of the address space of the new process:

1. The child process is a duplicate of the parent process.


2. The child process has a program loaded into it.

Process Termination

By making the exit(system call), typically returning an int, processes may request their own
termination. This int is passed along to the parent if it is doing a wait(), and is typically zero
on successful completion and some non-zero code in the event of any problem.

Processes may also be terminated by the system for a variety of reasons, including :

 The inability of the system to deliver the necessary system resources.


 In response to a KILL command or other unhandled process interrupts.
 A parent may kill its children if the task assigned to them is no longer needed i.e. if
the need of having a child terminates.
 If the parent exits, the system may or may not allow the child to continue without a
parent.

Cooperating processes

Cooperating processes are those that can affect or are affected by other processes running on
the system. Cooperating processes may share data with each other.

Reasons for needing cooperating processes

There may be many reasons for the requirement of cooperating processes. Some of these are
given as follows −

 Modularity

Modularity involves dividing complicated tasks into smaller subtasks. These subtasks
can completed by different cooperating processes. This leads to faster and more
efficient completion of the required tasks.

 Information Sharing

Sharing of information between multiple processes can be accomplished using


cooperating processes. This may include access to the same files. A mechanism is
required so that the processes can access the files in parallel to each other.

 Convenience

There are many tasks that a user needs to do such as compiling, printing, editing etc.
It is convenient if these tasks can be managed by cooperating processes.

 Computation Speedup

Subtasks of a single task can be performed parallely using cooperating processes. This
increases the computation speedup as the task can be executed faster. However, this is
only possible if the system has multiple processing elements.

Methods of Cooperation

Cooperating processes can coordinate with each other using shared data or messages. Details
about these are given as follows −

Cooperation by Sharing

The cooperating processes can cooperate with each other using shared data such as memory,
variables, files, databases etc. Critical section is used to provide data integrity and writing is
mutually exclusive to prevent inconsistent data.

A diagram that demonstrates cooperation by sharing is given as follows –


 In the above diagram, Process P1 and P2 can cooperate with each other using shared data
such as memory, variables, files, databases etc.

 Cooperation by Communication

The cooperating processes can cooperate with each other using messages. This may lead to
deadlock if each process is waiting for a message from the other to perform a operation.
Starvation is also possible if a process never receives a message.

A diagram that demonstrates cooperation by communication is given as follows −

In the above diagram, Process P1 and P2 can cooperate with each other using messages to
communicate.

You might also like