1 - Os Process Lecture 5

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 30

Chapter : Processes

By: Navjot Kaur


Chapter : Processes

 Process Concept

 Process Scheduling

 Operations on Processes
Process
Program: Passive entity
 Process is instance of a program under
executing
 Process – a program in execution
– Active Entity b/c it has Program
Counter associated to it.

 Process execution must progress in


sequential manner
 A process includes:
 program counter
 stack
 data section
Process
 A process has text section/ code section.

 It also includes the current activity, as represented by


the value of the program counter and the contents of
the processor’s registers.

 A process also includes the process stack, which


contains:
 temporary data (such as function parameters,
return addresses, and local variables)
 data section, which contains global variables.

 A process may also include a heap, which is memory


that is dynamically allocated during process run time.
Process
 A program is a passive entity, such as a file
containing a list of instructions stored on disk.

 A process is an active entity with a program


counter specifying the next instruction to
execute and a set of associated resources.
Process States
 As a process executes, it changes state
 new: The process is being created
 ready: The process is waiting to be
assigned to a processor and is ready to
get executed
 running: Instructions are being executed
 waiting: The process is waiting for some
event to occur/ waiting for resources
 terminated: The process has finished
execution
Process States
Process Control Block (PCB)
Process Control Block (PCB, also called Task
Controlling Block) is a data structure in the
operating system kernel containing the
information needed to manage a particular
process.

The PCB is "the manifestation of a process in an


operating system".
Process Control Block (PCB)
Information associated with each process:
1. Process State- new, ready….etc.
2. Pointer- to the parent process
3. Program Counter- next instruction to be
executed.
4. Process Number- Unique identification number
in OS
5. CPU Registers- Various CPU registers where
process need to be stored for execution for
running state.
6. CPU Scheduling Information- Process Priority
and other info. required for scheduling
Process Control Block (PCB)
7. Memory-Management Information- Registers,
Page tables (where process is saved)used by
OS

8. Accounting Information- For how long CPU and


other resources are allocated to process

9. I/O Status Information- List of devices


allocated to the process
Process Control Block (PCB)
Context Switch
When CPU switches
to another
process, the
system must save
the state of the
old process in the
stack and load
the saved state
for the new
process or reload
the state of
current process
from stack.
Context Switch
 Switching the CPU to another process requires
saving the state of the old process and loading
the saved state for the new process. This task is
known as a context switch.
 The context of a process is represented in the
Process Control Block(PCB) of a process;
 it includes the value of the CPU registers, the
process state and memory-management
information.
 When a context switch occurs, the Kernel saves
the context of the old process in its PCB and
loads the saved context of the new process
scheduled to run.
Context Switch
 Context switch time is pure overhead, because
the system does no useful work while switching.
 Its speed varies from machine to machine,
depending on the memory speed, the number of
registers that must be copied, and the existence
of special instructions(such as a single
instruction to load or store all registers).
 Typical speeds range from 1 to 1000
microseconds.
CPU Switch From Process to
Process
Scheduling Queues
 The activity 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.
Scheduling Queues
Schedulers fall 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 favor another process, pre-
empting the currently executing process.
Scheduling Queues
 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.
Scheduling Queues
 The OS maintains all 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.
Process Scheduling Queues
 Job queue − This queue keeps all the
processes in the system.

 Ready queue − This queue keeps a set of all


processes residing in main memory, ready and
waiting to execute.
 A new process is always put in this queue.

 Device queues − The processes which are


blocked due to unavailability of an I/O device
constitute this queue.
Process Scheduling Queues
Ready Queue And Various I/O Device Queues
Ready Queue is implemented using Linked
List
Representation of Process Scheduling

Queuing Diagram
MCQ
1. CPU performance is
measured through ________.
 a. Throughput
 b. MHz
 c. Flaps
 d. None of the above
MCQ
1. a
MCQ

2. Which of the following is a criterion to


evaluate a scheduling algorithm?
a. CPU Utilization: Keep CPU utilization as
high as possible
b. Throughput: number of processes
completed per unit time
c. Waiting Time: Amount of time spent ready
to run but not running
d. All of the above
MCQ
2. d
MCQ
3. _________ does the job of allocating a
process to the processor.
a. Long term scheduler
b. Short term scheduler
c. Medium term scheduler
d. Dispatcher
MCQ
3. d
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

You might also like