0% found this document useful (0 votes)
4 views30 pages

Lect 4

Uploaded by

Muhammad Farhan
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)
4 views30 pages

Lect 4

Uploaded by

Muhammad Farhan
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/ 30

OPERATING

SYSTEM (O.S)
Lect-5
PROCESS MANAGEMENT

Total 24 slides
PROCESS
 A process is a program in execution , in different O.s process may
called job or Activity
 A process is a unit of work in some system
 A program in execution is called Process

A process include:
 Program counter (to indicate the current activity)
 Stack (keep temporary data)
 Data Section( global variable)
Total 24 slides
 If you run same application program twice it means you create
two process
For Example
 If you open two editor in two different windows each editor is a
separate process
 A C.P.U may shared among many process
 Active process May either be waiting to the C.P.U or executing on
it
 A process which is waiting for the C.P.U is ready and a process
which has been allocated to the C.P.U is running

Total 24 slides
OPERATIONS ON THE PROCESS

1. Creation
 Once the process is created, it will be ready and come into the ready queue (main
memory) and will be ready for the execution.
2. Scheduling
 Out of the many processes present in the ready queue, the Operating system chooses one
process and start executing it. Selecting the process which is to be executed next, is
known as scheduling.
3. Execution
 Once the process is scheduled for the execution, the processor starts executing it.
Process may come to the blocked or wait state during the execution then in that case the
processor starts executing the other processes.
4. Deletion/killing
 Once the purpose of the process gets over then the OS will kill the process. The Context
of the process (PCB) will be deleted and the process gets terminated by
Totalthe Operating
24 slides
Process
States

PROCESS STATES
New Active Waiting Halt
 As the process executes, it changed its states.
 Each process may be in one of the following state:
Ready Running

Total 24 slides
PROCESS STATES
 New: A process is being created
 Active: Active process may either be waiting for the C.P.U or executing
on it
 Ready: A process which is waiting for the C.P.U
 Running: Instruction are being executed
 Waiting: A process which is waiting for an event(e.g, I/O)
 Halt: A process terminate when interrupt occurs.
 Terminate: The process has finished execution.
New Active Halt

Terminated
Waiting Total 24 slides
DETAIL DIAGRAM

Total 24 slides
PROCESS CONTROL BLOCK(PCB)
 While creating a process, the operating system performs several
operations. To identify the processes, it assigns a process identification
number (PID) to each process.
 The process control block (PCB) is used to track the process’s execution
status.
 Each block of memory contains information about the process state,
program counter, stack pointer, status of opened files etc.
 All this information is required and must be saved when the process is
switched from one state to another.

Total 24 slides
PROCESS CONTROL BLOCK(PCB)
 When the process makes a transition from one state to another,
the operating system must update information in the process’s
PCB.
 A process control block (PCB) contains information about the
process, i.e. registers, quantum, priority, etc.
 Each process is represented in the operating system by a
process control block (PCB) also called a task control block.
 The information of the Process is used by the CPU at the Run
time.
 There’s a data structure called the process control block (PCB)
that holds all this stuff.
 The PCB serves as the repository for any information which can
vary from process to process.
Total 24 slides
PROCESS CONTROL BLOCK(PCB)
PCB CONTAINS MANY PIECES OF INFORMATION ASSOCIATED WITH
A SPECIFIC PROCESS WHICH ARE DESCRIBED BELOW.

 Pointer: It is a stack pointer that is required to be saved when the process is


switched from one state to another to retain the current position of the
process. It is used for maintaining a scheduling list.
 Process state: It stores the respective state of the process.( Running or
waiting)
 Process number: Every process is assigned a unique id known as process ID
or PID which stores the process identifier.
 Program counter: It stores the counter,: which contains the address of the
next instruction that is to be executed for the process.
 Register: These are the CPU registers which include all process-centric
register
 Memory limits: This field contains the information about memory
management system used by the operating system.
 Open files list : This information includes the list of files opened for a
process.
Total 24 slides
ROLE OF PROCESS CONTROL
BLOCK(PCB)
The PCB is identified by an integer process ID (PID)The various
information which is Stored into the PCB as followings:

1) Name of the Process.


2) State of the Process. Means Ready, Active, Wait.
3) Resources allocated to the Process
4) Memory which is provided to the Process.
5) Scheduling information.
6) Input and Output Devices used by the Process.
7) Process ID or a Identification Number which is given by the CPU when
a Process Request for a Service.
Total 24 slides
PROCESS SCHEDULING

 The 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 on the basis of a particular strategy.
 When more than one process is runnable, the O.S must decide which one first to
run
 The part of the O.S concerned with the decision is called the Scheduler and
algorithm it uses called Scheduling Algorithm.
 Any recourses before utilization it must be schedule
 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 loaded process shares the CPU using time
multiplexing.

Total 24 slides
PROCESS SCHEDULING

Through Scheduling:
 Response Time: Scheduler minimize the response time for users
 Turn-around Time: Scheduler minimize the Turn-around time for
users
 C.P.U Utilization: Scheduler maximize the C.P.U utilization
 Throughput: Scheduler maximize the no. of jobs per unit time

Total 24 slides
CATEGORIES OF SCHEDULING

 There are two categories of scheduling:

 Non-preemptive: Here the resource can’t be taken from a process


until the process completes execution. The switching of resources
occurs when the running process terminates and moves to a
waiting state.

 Preemptive: Here the OS allocates the resources to a process for


a fixed amount of time. During resource allocation, the process
switches from running state to ready state or from waiting state
to ready state. This switching occurs as the CPU may give priority
to other processes and replace the process with higher priority
with the running process. Total 24 slides
PROCESS SCHEDULING QUES
 The OS maintains all Process Control Blocks (PCBs) in Process
Scheduling Queues. The OS maintains a separate queue for each
of the process states and PCBs of all processes in the same
execution state are placed in the same queue. When the state of a
process is changed, its PCB is unlinked from its current queue
and moved to its new state queue.
 Scheduling queues refers to queues of processes or devices.
 The operating system also maintains other queues such as device
queue.
 Device queue is a queue for which multiple processes are waiting
for a particular I/O device.
 Each device has its own device queue.
Total 24 slides
SCHEDULING QUES
 When the process enters into the system, then this process is put into a job
queue. This queue consists of all processes in the system.
 Process in memory, waiting to execute are in the Ready Que
 A Ready Header contain pointer to the first and last PCB in the list, each of
which has pointer to next PCB.
 Device Que: The list of process which are waiting for I/O Devices
 After a process in Ready Que is selected for execution
 It could be issue an I/O request and put in the I/O Que
 It could create a sub-process and wait for its termination
 It Could be interrupted and go to the Ready Que.

Total 24 slides
SCHEDULING QUES

THIS FIGURE SHOWS THE QUEUING DIAGRAM OF PROCESS


SCHEDULING.

Total 24 slides
Scheduling
Ques
TYPES OF SCHEDULING QUES
Job Que Ready Que Device Que

Shared
Dedicated Que
Que

Total 24 slides
TYPES OF SCHEDULING QUES
Job Que:
 When the process enters into the system, then this process is put into a
job queue. This queue consists of all processes in the system.
Ready Que:
 The process that are residing in main memory and wait for C.P.U are
kept in list called Ready Que
 Ready Que are implemented by link list, FIFO Que, Priority Que, Tree,
Stack etc.
Device Que:
 The process that are waiting for Device to become availaible or to
deliver data are placed in device Que
Total 24 slides
PROCESS SCHEDULING

 The act of determining which process in the ready state should be


moved to the running state is known as Process Scheduling.
 The prime aim of the process scheduling system is to keep the
CPU busy all the time and to deliver minimum response time for
all programs. For achieving this, the scheduler must apply
appropriate rules for swapping processes IN and OUT of CPU.
 Schedulers fell into one of the two general categories :
 Non pre-emptive scheduling. When the currently executing
process gives up the CPU voluntarily.
 Pre-emptive scheduling. When the operating system decides to
favour another process, pre-empting the currently executing
process.
Total 24 slides
Types of Scheduler
SCHEDULER:

 A process migrate between the various scheduling Ques throughout its


Long-Term Short-Term Medium-Term
Lifetime
scheduler scheduler scheduler
 Scheduler select process from these Ques
 Their main task is to select the jobs to be submitted into the system and to
decide which process to run .

Total 24 slides
LONG-TERM SCHEDULER/JOB SCHEDULER:

 It is also called job scheduler.


 Long term scheduler determines which programs are admitted to the
system for processing.
 Select process from pool and load them into memory for execution.
 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.
 I/O Bound Process: Spend more time for doing I/O than computation
 C.P.U Bound Process: Spend more time for doing Computation
Total 24 slides
SHORT-TERM SCHEDULER/C.P.U SCHEDULER:

 It is also called CPU scheduler.


 Main objective is increasing 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 process among the processes that are
ready to execute and allocates CPU for it.
 Short term scheduler also known as dispatcher, execute most
frequently and makes the fine grained decision of which process
to execute next.
 Short term scheduler is faster than long term scheduler.

Total 24 slides
MEDIUM-TERM SCHEDULER/C.P.U
SCHEDULER:

 Medium term scheduling is part of the 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.
 Running process may become suspended if it makes an I/O request.
 Suspended processes cannot make any progress towards completion.
 In this condition, to remove the process from memory and make space for
other process, 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. Total 24 slides
COMPARISON BETWEEN
SCHEDULER

Total 24 slides
CONTEXT SWITCH
 The Context switching is a technique or method used by the operating
system to switch a process from one state to another to execute its
function using CPUs in the system.
 When switching perform in the system, it stores the old running
process's status in the form of registers and assigns the CPU to a new
process to execute its tasks.
 While a new process is running in the system, the previous process
must wait in a ready queue.
 The execution of the old process starts at that point where another
process stopped it.
 It defines the characteristics of a multitasking operating system in
which multiple processes shared the same CPU to perform multiple
tasks without the need for additional processors in the system.
Total 24 slides
NEED OF CONTEXT SWITCHING

 Suppose that multiple processes are stored in a Process Control


Block (PCB). One process is running state to execute its task with
the use of CPUs. As the process is running, another process
arrives in the ready queue, which has a high priority of
completing its task using CPU. Here we used context switching
that switches the current process with the new process requiring
the CPU to finish its tasks. While switching the process, a context
switch saves the status of the old process in registers. When the
process reloads into the CPU, it starts the execution of the
process when the new process stops the old process. If we do not
save the state of the process, we have to start its execution at the
initial level. In this way, context switching helps the operating
system to switch between the processes, store or reload the
process when it requires executing its tasks.
Total 24 slides
As we can see in the diagram, initially, the P1
process is running on the CPU to execute its
task, and at the same time, another process, P2,
is in the ready state. If an error or interruption
has occurred or the process requires
input/output, the P1 process switches its state
from running to the waiting state. Before
changing the state of the process P1, context
switching saves the context of the process P1 in
the form of registers and the program counter to
the PCB1. After that, it loads the state of the P2
process from the ready state of the PCB2 to the
running state.

Total 24 slides
 The following steps are taken when switching Process P1 to Process 2:
 First, thes context switching needs to save the state of process P1 in the form of the program
counter and the registers to the PCB (Program Counter Block), which is in the running state.
 Now update PCB1 to process P1 and moves the process to the appropriate queue, such as the
ready queue, I/O queue and waiting queue.
 After that, another process gets into the running state, or we can select a new process from
the ready state, which is to be executed, or the process has a high priority to execute its task.
 Now, we have to update the PCB (Process Control Block) for the selected process P2. It
includes switching the process state from ready to running state or from another state like
blocked, exit, or suspend.
 If the CPU already executes process P2, we need to get the status of process P2 to resume its
execution at the same time point where the system interrupt occurs.
Similarly, process P2 is switched off from the CPU so that the process P1 can resume execution.
P1 process is reloaded from PCB1 to the running state to resume its task at the same point.
Otherwise, the information is lost, and when the process is executed again, it starts execution at
the initial level.

Total 24 slides

You might also like