0% found this document useful (0 votes)
30 views28 pages

unit 2 - process management

The document provides an overview of process management in operating systems, detailing the concept of a process, its lifecycle, and the differences between processes and programs. It discusses the Process Control Block (PCB), process states, context switching, inter-process communication, and various scheduling strategies and algorithms. Additionally, it highlights the importance of resource allocation and the mechanisms for process creation and termination.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views28 pages

unit 2 - process management

The document provides an overview of process management in operating systems, detailing the concept of a process, its lifecycle, and the differences between processes and programs. It discusses the Process Control Block (PCB), process states, context switching, inter-process communication, and various scheduling strategies and algorithms. Additionally, it highlights the importance of resource allocation and the mechanisms for process creation and termination.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Process Management

Unit 2
Concept of a Process
• A process is essentially running software. The execution of any
process must occur in a specific order.
• A process refers to an entity that helps in representing the
fundamental unit of work that must be implemented in any system.

Temporary data

Structure/Layout of
process in memory

Provide dynamic memory allocation to running process

Static,global variabe

PC & contents of register


Difference between process and program
Process
Program

Programs in OS are a static sequence of The process is an active instance of a


Definition
instructions stored in a file. program in execution.

Storage Stored in Disk. Reside in main memory during execution.

Execution It can’t execute by itself. Executed by the system.

Resource Allocation Doesn’t have any resources. Has resources like memory and CPU .

Instance Single instance on disk. Multiple instances can run concurrently.

Dependency It can exist without a process. It can’t exist without a program.

Entity Type Passive Entity Active Entity

It can communicate with other


Doesn’t interact with other programming
Interaction programming languages with inter-process
languages.
communication.

It follows the steps such as ready, running,


Lifecycle If not modified, it remains for a lifetime.
and terminated.
Process control Block
• The Process Control Block (PCB) is a data structure
associated with each process in an operating
system.
• It holds essential information about the process,
such as its current state, unique process identifier
(PID), CPU registers, memory management details,
and file descriptors.
• Also called task control block
Process state
Two state process
model
5 state transition
diagram

6 state
transition
Process State Description
New The process is being created.
The process is waiting to be assigned to
Ready
the CPU.
The process is currently being executed by
Running
the CPU.
The process is waiting for some event to
Waiting
occur, such as an I/O operation.
The process has finished execution and is
Terminated
being removed from memory.
Present in Memory State

Secondary Memory New state

Main Memory Ready state

Main Memory Run state

Main Memory Wait state

Secondary Memory Suspend wait state

Secondary Memory Suspend ready state


Process Description
• OS constructs and maintains
tables of information about
each entity that it is managing
: memory tables, IO tables,
file tables, process tables.
• Process control block:
Associated with each process
are a number of attributes
used by OS for process
control. This collection is
known as PCB.
• Process image: Collection of
program, data, stack, and PCB
together is known as Process
image.
• An OS maintains the following tables for
managing processes and resources:
– Memory tables
– I/O tables
– File tables
– Process tables
Process Operations/Control-Process creation
• Four common events that lead to a process creation
are:
• 1) When a new batch-job is presented for execution.
• 2) When an interactive user logs in.
• 3) When OS needs to perform an operation (usually
IO) on behalf of a user process, concurrently with that
process.
• 4) To exploit parallelism an user process can spawn a
number of processes.
==> concept of parent and child processes.
How the operating system creates
a process:
• Load code and data into
memory.
• Create and initialize process
control block.
• Create first thread with call
stack.
• Provide initial values for "saved
state" for the thread.
• Make process known to
dispatcher; dispatcher
"resumes" to start of new
program.
Process Termination
• Normal completion, time limit exceeded, memory
unavailable
• Bounds violation, protection error, arithmetic error, invalid
instruction
• IO failure, Operator intervention, parent termination, parent
request
• A number of other conditions are possible.
• Segmentation fault : usually happens when you try
write/read into/from a non-existent array/structure/object
component. Or access a pointer to a dynamic data before
creating it. (new etc.)
• Bus error: Related to function call and return. You have
messed up the stack where the return address or
parameters are stored.
• A process terminates when it finishes executing its final
statement and asks the operating system to delete it by
using the exit () system calL At that point, the process
may return a status value (typically an integer) to its
parent process (via the wait() system call).
Context Switching
• Context switching in an
operating system involves
saving the context or state of a
running process so that it can
be restored later, and then
loading the context or state of
another. process and run it.
• Context Switching refers to the
process/method used by the
system to change the process
from one state to another using
the CPUs present in the system
to perform its job
Working Process Context Switching
• The state of the current process must be saved for
rescheduling.
• The process state contains records, credentials, and operating
system-specific information stored on the PCB or switch.
• The PCB can be stored in a single layer in kernel memory or in
a custom OS file.
• A handle has been added to the PCB to have the system ready
to run.
• The operating system aborts the execution of the current
process and selects a process from the waiting list by tuning
its PCB.
• Load the PCB’s program counter and continue execution in
the selected process.
• Process/thread values ​can affect which processes are
selected from the queue, this can be important.
Inter process communication
• A process can be of two types:
Independent process.
Co-operating process.
• An independent process is not affected by
the execution of other processes while a co-
operating process can be affected by other
executing processes
• there are many situations when co-
operative nature can be utilized for
increasing computational speed,
convenience, and modularity
• Inter-process communication (IPC) is a
mechanism that allows processes to
communicate with each other and
synchronize their actions
• method of co-operation
✓ Shared Memory
✓ Message passing
basic structure of communication
between processes
Shared memory process
communication
• Shared memory is an operating-system feature
that allows the database server threads and
processes to share data by sharing access to pools
of memory.
• The database server uses shared memory for the
following purposes:
• To reduce memory usage and disk I/O.
• To perform high-speed communication
between processes.
• Ex.Producer-consumer problem
Message passing
• processes communicate with each other
without using any kind of shared memory
• f two processes p1 and p2 want to
communicate with each other, they
proceed as follows
✓ Establish a communication link (if a
link already exists, no need to establish it
again.)
✓ Start exchanging messages using basic
primitives.
We need at least two primitives:
– send(message, destination) or s
end(message)
– receive(message, host) or
receive(message)
Process Sheduling
• Process scheduling is the activity of the process
manager that handles the removal of the running
process from the CPU and the selection of another
process based on a particular strategy.
• Process scheduling is an essential part of a
Multiprogramming operating system
Categories of Scheduling
• Non-preemptive: Here the resource can’t be taken
from a process until the process completes execution.
The switching of resources occurs when the running
process terminates and moves to a waiting state.
• Preemptive: Here the OS allocates the resources to a
process for a fixed amount of time. During resource
allocation, the process switches from running state to
ready state or from waiting state to ready state. This
switching occurs as the CPU may give priority to other
processes and replace the process with higher priority
with the running process.
Types of Schedulers
• Long-term Scheduler (Job Scheduler):Determines
which processes enter the ready queue.
• Invoked infrequently.
• Short-term Scheduler (CPU Scheduler):Decides
which ready process should be executed next.
• Invoked frequently and must be fast.
• Medium-term Scheduler:Manages swapping of
processes between main memory and disk.
• Used for handling multiprogramming and
optimizing memory usage.
Scheduling Criteria
• CPU Utilization: Maximize CPU usage to ensure it's
always processing tasks.
• Throughput: Maximize the number of processes
completed per time unit.
• Turnaround Time: Minimize the time taken from
process submission to its completion.
• Waiting Time: Minimize the time a process spends
waiting in the ready queue.
• Response Time: Minimize the time from process
submission until the first response is produced.
Types of Scheduling Algorithms
Types of Scheduling Algorithms
• First-Come, First-Served (FCFS):
Processes are executed in the order they arrive.Simple but can
lead to long waiting times.
• Characteristics of FCFS:
• Non-preemptive: The CPU cannot be taken away from the
running process.
• Simple: Easy to implement and understand.
• Fairness: Every process gets executed in the order of
arrival.
• Inefficient for CPU-bound processes: Can lead to the
"convoy effect" where short processes get stuck behind
long ones.

You might also like