Ch. 2 ... Part - 1
Ch. 2 ... Part - 1
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 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.
• 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
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
• Processes
• Process Structure
• Process Scheduling
• Scheduling Algorithms
• Process Synchronization & Deadlocks
• Thread Management
• Memory Management
• System Calls
• File System
Multiprogramming
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:
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:
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: