0% found this document useful (0 votes)
20 views31 pages

Ch. 2 ... Part - 1

The document discusses process management and synchronization concepts including: - Processes are running instances of programs that require resources like memory and CPU. - Processes can be in different states like ready, running, waiting, and terminated. Context switching involves saving/loading process contexts when changing states. - A process control block stores information about each process like state, memory, and scheduling. Scheduling algorithms determine which ready process runs next on CPU.

Uploaded by

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

Ch. 2 ... Part - 1

The document discusses process management and synchronization concepts including: - Processes are running instances of programs that require resources like memory and CPU. - Processes can be in different states like ready, running, waiting, and terminated. Context switching involves saving/loading process contexts when changing states. - A process control block stores information about each process like state, memory, and scheduling. Scheduling algorithms determine which ready process runs next on CPU.

Uploaded by

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

Process

Management
and
CH. 2 Synchronization
BY DR. VEEJYA KUMBHAR
Ch. 2
Process Management and Synchronization
Syllabus
• Process Management and Synchronization
• PCB
• Job and processor scheduling
• Problems of concurrent processes- Critical
sections, Mutual exclusion, Synchronization
• Deadlock
• Device and File Management
Process

Definitions:
 A process is basically a program in execution.
 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.
 E.g. .c, .cpp, .java , .py are the programs. When we double click on .exe or type as ./a.out…the
code gets occupied by some space in memory.
Process Vs Program
Process Program
A Program is basically a collection of
The process is basically an instance of the
instructions that mainly performs a specific
computer program 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 as memory, A Program is stored by hard-disk and does not
CPU, Input-Output devices. require any resources.
A process has a dynamic instance of code and
A Program has static code and static data.
data
Basically, a process is the running instance of On the other hand, the program is
the code. the executable code.
Process States

States of Process: A process is in one of the following states:

1. New: Newly Created Process (or) being-created process.


2. Ready: After creation process moves to Ready state, i.e. the
process is ready for execution.
3. Run: Currently running process in CPU (only one process at a time
can be under execution in a single processor).
4. Wait (or Block): When a process requests I/O access.
5. Complete (or Terminated): The process completed its execution.
6. Suspended Ready: When the ready queue becomes full, some processes
are moved to suspended ready state
7. Suspended Block: When waiting queue becomes full.
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.
When does context switching happen?

1. When a high-priority process comes to a ready state (i.e.


with higher priority than the running process)
2. An Interrupt occurs
3. User and kernel-mode switch
4. Preemptive CPU scheduling used ( Time Run Out-TRO).
5. When the process is terminated.
Context Switch vs Mode Switch:

A mode switch occurs when the CPU privilege level is changed, for example
when a system call is made, or a fault occurs.
The kernel works in more a privileged mode than a standard user task.
If a user process wants to access things that are only accessible to the kernel,
a mode switch must occur.
The currently executing process need not be changed during a mode switch.
A mode switch typically occurs for a process context switch to occur.
Only the kernel can cause a context switch.
CPU-Bound vs I/O-Bound Processes

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.


Ch. 4 Operating System Services Syllabus

• Processes 
• Process Structure
• PCB
• Synchronization
• Job and processor scheduling
• Problems of concurrent processes-
• Critical sections,
• Mutual exclusion,
• Synchronization
• Deadlock
• Device and File Management
Process Structure
Process Structure

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.
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 - CPU register holds the registers required by the program
and 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.
Process Control Block

•I/O Status information: Devices allocated, open file tables, etc.


Ch. 4 Operating System Services Syllabus

• Processes 
• Process Structure 
• Process Scheduling
• Scheduling Algorithms
• Process Synchronization & Deadlocks
• Thread Management
• Memory Management
• System Calls
• File System
Multiprogramming

Multiprogramming – We have many processes ready to run.


There are two types of multiprogramming:
1.Pre-emption – Process is forcefully removed from CPU.
Pre-emption is also called as time sharing or multitasking.
2.Non pre-emption – Processes are not removed until they complete the
execution.
Degree of multiprogramming – The number of processes that can reside in the
ready state at maximum decides the degree of multiprogramming,
e.g., if the degree of programming = 100, this means 100 processes can reside in
the ready state at maximum.
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.
Process Scheduling

 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.
 Such operating systems allow more than one process to be loaded into the executable
memory at a time and the loaded process shares the CPU using time multiplexing.
• All processes, upon entering into the system, are stored in the Job
Queue.
Scheduling
• Processes Queues
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:

1. Long term – performance – Decides about how many processes should be made to stay in
the ready state, this decides the degree of multiprogramming. Once a decision is taken it
lasts for a long time hence called long term scheduler.
2. Short term – Context switching time – Short term scheduler will decide which process to
be executed next and then it will call dispatcher. A dispatcher is a software that moves
process from ready to run and vice versa. In other words, it is context switching.
3. Medium term – Swapping time – Suspension decision is taken by medium term scheduler.
Medium term scheduler is used for swapping that is moving the process from main memory
to secondary and vice versa.
Long Term or job scheduler:

 It brings the new process to the ‘Ready State’.


 It controls the Degree of Multi-programming, i.e., the number of processes
present in a ready state at any point in time.
 It is important that the long-term scheduler make a careful selection of both I/O
and CPU-bound processes.
 I/O-bound tasks are which use much of their time in input and output
operations while CPU-bound processes are which spend their time on the CPU.
 The job scheduler increases efficiency by maintaining a balance between the
two.
 They operate at a high level and are typically used in batch-processing systems.
Long Term
Schedular

Long Term
Schedular
Short-term or CPU scheduler:

It is responsible for selecting one process from the ready state for
scheduling it on the running state.
Note:
• Short-term scheduler only selects the process to schedule it doesn’t
load the process on running.
• The CPU scheduler is responsible for ensuring there is no starvation
owing to high burst time processes.
Short-term or CPU scheduler:

The dispatcher is responsible for loading the process selected by the


Short-term scheduler on the CPU (Ready to Running State) . Context
switching is done by the dispatcher only.

A dispatcher does the following:

1. Switching context.
2. Switching to user mode.
3. Jumping to the proper location in the newly loaded program.
Short Term
Schedular

Dispatcher

Dispatcher
Medium-term scheduler:

 It is responsible for suspending and resuming the process.


 It mainly does swapping (moving processes from main memory to disk and vice
versa).
 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.
 It is helpful in maintaining a perfect balance between the I/O bound and the CPU
bound.
 It reduces the degree of multiprogramming.
Medium Term
Schedular
Medium Term
Schedular
Other Schedulers

 I/O schedulers: I/O schedulers are in-charge of managing the execution


of I/O operations such as reading and writing to discs or networks. They
can use various algorithms to determine the order in which I/O
operations are executed, such as FCFS (First-Come, First-Served) or RR
(Round Robin).
 Real-time schedulers: In real-time systems, real-time schedulers ensure
that critical tasks are completed within a specified time frame. They can
prioritize and schedule tasks using various algorithms such as EDF
(Earliest Deadline First) or RM (Rate Monotonic).
Thank
You

You might also like