Process-Management (2)
Process-Management (2)
Process States:
When a process executes, it passes through different states. These stages may differ in
different operating systems.
In general, a process can have one of the following five states at a time.
The architecture of a PCB is completely dependent on Operating System and may contain
different information in different operating systems. Here is a simplified diagram of a PCB −
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.
Schedulers:
Schedulers are special system software which handle process scheduling in various
ways.
Their main task is to select the jobs to be submitted into the system and to decide
which process to run. Schedulers are of three types −
Long-Term Scheduler
Short-Term Scheduler
Medium-Term Scheduler
Long Term Scheduler
It is also called a job scheduler.
A long-term scheduler determines which programs are admitted to the system for
processing.
It selects processes from the queue and loads them into memory for execution.
Process loads into the memory for CPU scheduling.
The primary objective of the job scheduler is to provide a balanced mix of jobs, such
as I/O bound and processor bound.
It also controls the degree of multiprogramming.
If the degree of multiprogramming is stable, then the average rate of process
creation must be equal to the average departure rate of processes leaving the system.
On some systems, the long-term scheduler may not be available or minimal.
Time-sharing operating systems have no long term scheduler.
When a process changes the state from new to ready, then there is use of long-term
scheduler.
Short Term Scheduler:
It is also called as CPU scheduler.
Its main objective is to increase system performance in accordance with the chosen
set of criteria.
It is the change of ready state to running state of the process.
CPU scheduler selects a process among the processes that are ready to execute and
allocates CPU to one of them.
Short-term schedulers, also known as dispatchers, make the decision of which
process to execute next. Short-term schedulers are faster than long-term schedulers.
Medium Term Scheduler
Medium-term scheduling is a part of swapping.
It removes the processes from the memory.
It reduces the degree of multiprogramming.
The medium-term scheduler is in-charge of handling the swapped out-processes.
A running process may become suspended if it makes an I/O request.
A suspended process cannot make any progress towards completion.
In this condition, to remove the process from memory and make space for
other processes, the suspended process is moved to the secondary storage.
This process is called swapping, and the process is said to be swapped out or rolled
out.
Swapping may be necessary to improve the process mix.
Comparison among Scheduler
S.N. Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler
1 It is a job scheduler It is a CPU scheduler It is a process
swapping scheduler.
2 Speed is lesser than Speed is fastest among Speed is in between both
short term scheduler other two short and long term
scheduler.
3 It controls the degree of It provides lesser control It reduces the degree
multiprogramming over degree of of multiprogramming.
multiprogramming
4 It is almost absent or It is also minimal in time It is a part of Time sharing
minimal in time sharing sharing system systems.
system
5 It selects processes from It selects those processes It can re-introduce the
pool and loads them which are ready to process into memory and
into memory for execution execute execution can be continued.
Context Switch:
A context switch is the mechanism to store and restore the state or context of a CPU
in Process Control block so that a process execution can be resumed from the same
point at a later time.
Using this technique, a context switcher enables multiple processes to share a single
CPU.
Context switching is an essential part of a multitasking operating system features.
When the scheduler switches the CPU from executing one process to execute
another, the state from the current running process is stored into the process control
block.
After this, the state for the process to run 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.
To avoid the amount of context switching time, some hardware systems employ two
or more sets of processor registers.
When the process is switched, the following information is stored for later use.
Program Counter
Scheduling information
Base and limit register value
Currently used register
Changed State
I/O State information
Accounting information
3.3 Inter-process Communication
Processes executing concurrently in the operating system might be either
independent processes or cooperating processes.
A process is independent if it cannot be affected by the other processes executing in
the system.
Inter Process Communication (IPC) is a mechanism that involves communication of
one process with another process. This usually occurs only in one system.
Communication can be of two types −
Between related processes initiating from only one process, such as parent and
child processes.
Between unrelated processes, or two or more different processes.
Processes can communicate with each other using these two ways:
Shared Memory
Message passing
Shared Memory
Shared memory is the memory that can be simultaneously accessed by multiple
processes.
This is done so that the processes can communicate with each other.
All POSIX systems, as well as Windows operating systems use shared memory.
Message Queue
Multiple processes can read and write data to the message queue without being
as follow:
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:
Page 10 of
12
Many to One Model
Many-to-one model maps many user level threads to one Kernel-level thread. Thread
management is done in user space by the thread library. When thread makes a
blocking system call, the entire process will be blocked. Only one thread can access
the Kernel at a time, so multiple threads are unable to run in parallel on
multiprocessors.
If the user-level thread libraries are implemented in the operating system in such a way
that the system does not support them, then the Kernel threads use the many-to-one
relationship modes.
e
12
of
One to One Model
1
There is one-to-one relationship of user-level thread to the kernel-level thread. This
model provides more concurrency than the many-to-one model. It also allows another
2
thread to run when a thread makes a blocking system call. It supports multiple threads
to execute in parallel on microprocessors.
Disadvantage of this model is that creating user thread requires the
corresponding Kernel thread. OS/2, windows NT and windows 2000 use one to one
relationship model.
1 User-level threads are faster to create Kernel-level threads are slower to create
and manage. and manage.
3 User-level thread is generic and can run Kernel-level thread is specific to the
on any operating system. operating system.