Processor Management
Processor Management
Process
A process (task) is a single instance of an executable program. The sequential fashion is used to execute of
processes.
A process will need definite resources to complete its task — CPU time, memory, files and I/O devices.
Process is an active entity, which requires a set of resources to perform its function, including a processor
and special registers.
Suppose , computer programs are written in a text file and when it executes, it becomes a process which
completes all tasks stated in the program.
A program is converted process when it is loaded into the memory.
All these processes may execute concurrently (parallelism occur).
It can be divided into four sections (a basic layout of a process inside main memory) ─ stack, heap, text and
data.
Process Contd..
Stack
The process, Stack contains the temporary data such as method/function parameters, return address and
local variables.
Heap
This is dynamically allocated memory to a process during its run time.
Text
This contains the current activity denoted by the value of
Program Counter and contents of the processor's registers.
Data
This section contains the global and static variables.
Program
A program (job) is a portion of code which may be one or more lines.
A computer program is written by a programmer using programming language.
A program (job) is a unit of work that has been submitted by user to OS.
To compare a program with a process, a process is a dynamic instance of a computer program.
Thread
A portion of a process that can run independently.
A thread is also called a lightweight process.
Threads provide a way to improve application performance thorough parallelism.
Processor ( CPU)
A component of computer that performs calculations and executes programs.
In Multiprogramming Concept, the processor be “allocated” to each program or to each process for a period
of time and “deallocated” at an right moment.
Interrupt
Call for help.
Activates higher-priority program.
RUNNING
Scheduler dispatch
FINISHED I/O or event completion I/O or event wait
Waiting
Interrupt
Context Switch
It is the method to store and restore the state/context of a CPU in PCB.
A process execution can be resumed from the same point at a later time.
Here, a context switcher allows multiple processes to share a single CPU.
When the scheduler switches the CPU from executing one process to
execute another, the state from the current running process is stored into
the PCB.
After this, the state for the process to execute next is loaded from its own
PCB and used to set the PC, registers, etc. At that point, the second
process can start executing.
Context switches are computationally intensive since register and
memory state must be saved and restored.
Types of process scheduling
Preemptive scheduling policy
It is based on priority where a scheduler may preempt/block a low priority running process anytime
when a high priority process enters into a ready state.
Interrupts processing of a job and transfers the CPU to another job.
Non-preemptive scheduling policy
Functions without external interrupts.
Once a job allocates processor and starts execution, it remains in RUNNING state until it completes
its allotted time.
Until it issues an I/O request (natural wait) or until it is finished (exception for infinite loops).
FCFS Example
Process CPU Burst (Turnaround Time)
A 15 milliseconds
B 2 milliseconds
C 1 millisecond
Impossible to implement in shared systems where CPU time is not known in advance.
The processer should know how much time process will take to execute in advance.
The processes with equal priority are executed on first come first served basis.
The priority can be decided based on memory requirements, time requirements or any other resource
requirements.
Deadlocks
In a multiprogramming system, processes request resources. If those resources are actuality used by other
processes then the process enters into a waiting state. Though, if other processes are also in a waiting state,
then deadlock occur.
Definition –
A set of processes is in a deadlock state if every process in the set is waiting for an event (resource) that can
only be caused by some other process in the same set.
Example –
Process-1 requests the printer, gets it
Process-2 requests the tape unit, gets it Process-1 and Process-2 Process-1 requests the tape unit,
waits are deadlocked!
Process-2 requests the printer, waits
Resources
Resource: a process uses it
Normally limited (at least somewhat)
Examples of computer resources
Printers
Locks
Tapes
Tables (in a database)
Processes need access to resources in practical order
Two types of resources:
Preemptable resources: taken away from a process with no ill effects
Nonpreemptable resources: cause the process to fail if taken away
B A
Conditions for Deadlock
Conditions to produce a deadlock phenomenon.
Mutual exclusion
Each resource is assigned to at most one process.
Hold and wait
A process holding resources can request more resources.
No preemption
Previously granted resources cannot be compulsorily taken away.
Circular wait
There must be a circular sequence of two/more processes where one is waiting for a resource held
by the next member of the sequence.
Deadlock Prevention
Deadlock can be totally prohibited.
Confirm that at least one of the conditions for deadlock never happens
Mutual exclusion
Hold & wait
No preemption
Circular wait
Eliminating mutual exclusion
All resources of the computer system have not sharable. Some resources like printers, processing units are
non-sharable. So it is not possible to stop deadlocks by denying mutual exclusion.
Principle –
Avoid assigning resource when not absolutely necessary
Few processes likely truly claim the resource