Process
Process
States of a Process
During the execution of a process, it undergoes a
number of states. So, in this section of the blog, we will
learn various states of a process during its lifecycle.
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
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.
What is CPU Scheduling?
CPU Scheduling is a process of determining which process will
own CPU for execution while another process is on hold. The
main task of CPU scheduling is to make sure that whenever the
CPU remains idle, the OS at least select one of the processes
available in the ready queue for execution. The selection
process will be carried out by the CPU scheduler. It selects one
of the processes in memory that are ready for execution.
Preemptive Scheduling
In Preemptive Scheduling, the tasks are mostly assigned with
their priorities. Sometimes it is important to run a task with a
higher priority before another lower priority task, even if the
lower priority task is still running. The lower priority task holds for
some time and resumes when the higher priority task finishes its
execution.
Non-Preemptive Scheduling
In this type of scheduling method, the CPU has been allocated
to a specific process. The process that keeps the CPU busy will
release the CPU either by switching context or terminating. It is
the only method that can be used for various hardware
platforms. That’s because it doesn’t need special hardware (for
example, a timer) like preemptive scheduling.
Minimize:
Waiting time: Waiting time is an amount that specific process
needs to wait in the ready queue.
Response time: It is an amount to time in which the request
was submitted until the first response is produced.
Turnaround Time: Turnaround time is an amount of time to
execute a specific process. It is the calculation of the total time
spent waiting to get into the memory, waiting in the queue and,
executing on the CPU. The period between the time of process
submission to the completion time is the turnaround time.
Interval Timer
Timer interruption is a method that is closely related to
preemption. When a certain process gets the CPU allocation, a
timer may be set to a specified interval. Both timer interruption
and preemption force a process to return the CPU before its
CPU burst is complete.
Most of the multi-programmed operating system uses some
form of a timer to prevent a process from tying up the system
forever.
What is Dispatcher?
It is a module that provides control of the CPU to the process.
The Dispatcher should be fast so that it can run on every context
switch. Dispatch latency is the amount of time needed by the
CPU scheduler to stop one process and start another.
Functions performed by Dispatcher:
Context Switching
Switching to user mode
Moving to the correct location in the newly loaded program.
Round-Robin Scheduling
Round robin is the oldest, simplest scheduling algorithm. The
name of this algorithm comes from the round-robin principle,
where each person gets an equal share of something in turn. It
is mostly used for scheduling algorithms in multitasking. This
algorithm method helps for starvation free execution of
processes.
P0 0-0=
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 1
Average Wait Time: (0+4+6+13) / 4 = 5.75
P0 0 5 0
P1 1 3 5
P2 2 8 14
P3 3 6 8
Waiting time of each process is as follows −
P0 0-0=0
P1 5-1=4
P2 14 - 2 = 12
P3 8-3=5
P0 0 5 1
P1 1 3 2
P2 2 8 1
P3 3 6 3
Process Wa
P0
P1 1
P2 1
P3
P0 (0 - 0) + (12 - 3) =
P1 (3 - 1) = 2
P2 (6 - 2) + (14 - 9) + (20 - 1
P3 (9 - 3) + (17 - 12) =