Upload
gaurav-mam
View
219
Download
0
Embed Size (px)
Citation preview
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 1/22
Operating Systems Slide 1 of 22
Operating Systems
Processes
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 2/22
Operating Systems Slide 2 of 22
Some Basics
Process: a program in execution
● Running a program may spawn (create) more
than one process
The terms job and process are often used
interchangeably
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 3/22
Operating Systems Slide 3 of 22
Process
● Process is more than program code (sometimes
called the text section)
● It also includes current activity, such as:
●
Program counter● Contents of registers
● Process stack (function parameters, return addresses,
local variables)
● Data section (contains global variables)
● Heap (memory dynamically allocated during run-
time)
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 4/22
Operating Systems Slide 4 of 22
Process in Memory
Text
Data
Heap
Stack● Two or more instances of
the same program are
treated distinctly
● Their text section may bethe same, but the data
section, heap and stack
will be different
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 5/22
Operating Systems Slide 5 of 22
Process State
As a process executes it changes state
The state of a process is defined in part by what
it is currently doing
● New: the process is being created
● Running: instructions are being executed
● Waiting: process is waiting for some event to
occur● Ready: waiting to be assigned to a processor
● Terminated: finished execution
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 6/22
Operating Systems Slide 6 of 22
Process State Diagram
TerminatedNew
Ready Running
Waiting
admitted
scheduler dispatch
interrupt
event completion event wait
exit
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 7/22
Operating Systems Slide 7 of 22
Process Control Block
Each process in the OS is represented by a Process
Control Block (aka task control block)
Contains information about the process:
●
Process state● Program counter
● CPU registers
● CPU-scheduling information
● Memory-management information
● Accounting information
● I/O status information
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 8/22
Operating Systems Slide 8 of 22
CPU Switch from Process to Process
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 9/22
Operating Systems Slide 9 of 22
Threads
Process model discussed so far implies that
processes execute in a single thread of execution
● Means only one thing can happen at a time
● Think of a thread as a sequence of execution
● Threads are a type of concurrency within a
process
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 10/22
Operating Systems Slide 10 of 22
Process Scheduling
Objective of multiprogramming is to have a
process running at all times, to maximize CPU
utilization
Objective of multitasking is to switch frequently& fast between processes so that user can
interact with all of them
Process Scheduler is the part of the OS thatselects one of the available processes for
execution on the CPU
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 11/22
Operating Systems Slide 11 of 22
Scheduling Queues
● As processes enter the system, they are put
into a job queue
● Processes in main memory that are ready &
waiting are put in the ready queue– Usually stored as a linked list
– Ready-queue header contains pointers to first & last
PCBs in the list
– Each PCB has a field that points to the next in the list
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 12/22
Operating Systems Slide 12 of 22
Scheduling Queues
● When processes need to use an I/O device and
have to wait for it, they enter its device
queue
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 13/22
Operating Systems Slide 13 of 22
Scheduling Queues: Visualization
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 14/22
Operating Systems Slide 14 of 22
Queuing Interactions
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 15/22
Operating Systems Slide 15 of 22
Schedulers
Processes move between various scheduling
queues during their lifetime
● Which process in any given queue should be
picked next?
The selection of a process from all the processes
in a queue is the job of the scheduler
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 16/22
Operating Systems Slide 16 of 22
Long- & Short-Term Schedulers
The Long-Term Scheduler (or job scheduler)
selects processes from the job pool and loads
them into memory for execution
The Short-Term Scheduler (or CPUscheduler) selects from among the processes
that are ready-to-execute for allocating the CPU
to
● Basic difference is in the frequency of execution
● Speed more important for CPU scheduler
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 17/22
Operating Systems Slide 17 of 22
Some Definitions
● Long-term scheduler controls the degree of
multiprogramming (the number of
processes in memory)
●
I/O-bound processes spend more of theirtime doing I/O
● CPU-bound processes spend more of their
time doing computations
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 18/22
Operating Systems Slide 18 of 22
Intricacies of Scheduling
● LTS has to choose a good mix of CPU-bound
& I/O-bound processes
● Too many CPU-bound processes – I/O devices
are under-utilized● Too many I/O-bound processes – CPU is
under-utilized
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 19/22
Operating Systems Slide 19 of 22
Medium-Term Scheduler
Medium-Term Scheduler manages the degree of
multiprogramming
– Removes processes from memory (& thus from CPU
contention)
– Later process can be re-loaded & execution continued
– This unloading & reloading process is called swapping
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 20/22
Operating Systems Slide 20 of 22
Switching Between Processes
● Interrupts cause OS to change CPU from
current task to run kernel routine
● Such events happen frequently
● When interrupt happens, OS needs to save
the context of currently-executing process so
that its state can be restored
● Essentially suspending the process & resuming it
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 21/22
Operating Systems Slide 21 of 22
Context of a Process
The context of a process is represented in its
PCB
● Value of CPU registers
● Process state
● Memory management information
8/4/2019 Lecture 09 (1)
http://slidepdf.com/reader/full/lecture-09-1 22/22
Operating Systems Slide 22 of 22
Context Switch
When switching from one process to another,
the OS performs a state save and then a state
restore
This process is called a context switch– This is pure overhead: no useful work is being done