0% found this document useful (0 votes)
7 views10 pages

Lecture 02 Process

The document explains the distinction between a program and a process, with a program being static instructions on disk and a process being a running instance of that program. It outlines the machine state of a process, including memory, registers, and the basic expectations of an operating system interface for process management. Additionally, it discusses how an OS creates and manages processes, including state transitions and the use of a Process Control Block (PCB) to track process information.

Uploaded by

Ryan Azim Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

Lecture 02 Process

The document explains the distinction between a program and a process, with a program being static instructions on disk and a process being a running instance of that program. It outlines the machine state of a process, including memory, registers, and the basic expectations of an operating system interface for process management. Additionally, it discusses how an OS creates and manages processes, including state transitions and the use of a Process Control Block (PCB) to track process information.

Uploaded by

Ryan Azim Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ProcessAbstraction

What is the difference blu and


a
programs process ?

program : static
instructions on disk

process: running program


For an analogy ,
a program could beansidered
as cake where as a process is
a
recipe ,
bout flour, timer etc.
like someone
baking the cake, with a
,
over
,

Goal of this chapter is to understand the notion of "process"-


Question : What is the machine state
item
of a process ?
what parts of machine are important for a
process ?
*
memory - >
-
instructions, data that program read/write
> address space
tells what's the next instruction
*
registers eg
:- program counter >
-

stack pointer > to


-

manage the stacker for


function parameters local variables etc..
,
devices for
A storage 110.

What are the basic expectations on


any interface of an
operating system ?
-create :
type a command into the shell/double-click on an icon,

the os needs to be invoked to create a process .

destroy :
If the process doesn't exit by itself, there should be a

provision to kill the process.

- wait : wait for andher process to stop .


running

-miscellaneous controls like suspend for sometime


and then resume.

-status : information about the processes.


But, how does an os
actually creates a
process ?
OS performs the
following steps to run a
programs

Sep1 :
Allocates memory and creates a
memory image

load its code and static data


A
any -is

from disk exe Like, initialized variables


A creates runtime stack, heap
stack > local variables , function
-

parameters,
return addresses , etc.

heap > -
for explicitly requested dynamically-
allocated data , for data structures like
linked lists ,
hash tables etc..

Step2: open basic files - STDIN, OUT, ERR

Steps: Initialize CPU


registers.
-

PC points to first instruction .

program counter
states of a
proces

currently executing on CPU) Running Ready Blocked

waiting tobe csuspended ,


not
scheduled) ready to run)
-
-
for read from the disk.
why Waiting
? some event ,
eg :- process lissues a

when the data is


When will it
unblocked ?
D1312 issues an interrupt .
ready

get
E (being ran)
some extra * New created, yet to
States * Dead (terminated)

state transition
Diagram-
so , concerned about single process.
far we were
only a

But we wish to run


many process in a
single system.
How toprovide theulusion of CPUs such that tens
many or
hundreds of the a
processescambe
run at samehie
the CPU.
-
allows users to run as
many
winmesharing
-

concurrent process as they


like

Example
-
-1 :

Two processes running ,


each of which only use the CPU (no 10)
2 : Processo
Example -
initiates 10.

>
-
could be
readingwriting
disk
on a or
waiting
for a packet from a

network

esta:
concerned
① which process to run at a particular point of time (policy)

② How to switch blu processes ? (mechanism)


?
policy mechanisms
Chigh-level intelligence) (low-level machinery)
2
scheduling algorithms be
protocols that needs to
implemented for
switching
egi-which programs to run ?
eg-how to do a context
now long to run this program ? -

etc... will learn switch ?


-

scheduling >
-
later M

Question : what to
--
keep in mind while
switching ?
Suspended game analogy :

Imaglise you are


playing several board games
(say, chess, monopoly, scrabble etc.) with friends ,
but

you only have are table .

you play one game at


So
time and when to
a
, you pause a game play
entire state↑ so
another
, you carefully saves its
track of anything.
you can return to it later without losing
need to ?
what all things you save

suspended board garse components operating systems equivalent


A Game ID or name * a
unique identifier (PID)
Memory image
* Game rules/settings * code data (static)
player notes cards in
, * stack and heap (dynamic
hands diceC etc.
,
tells which instruction
CPU context :
registers >
-
of the program
* whose turn it is ? * program counter
-
will execute
position of all
game pieces, etc. A current operands
-
next

* stack pointer manages the


-

file descripters stack of function parameters


,

* cards with drawn * parters to opened files and local


devices etc.. variables
etc
"suspend need to
carefully record the
..

When
i.,
you a
game you
,

and whose turn it is box up all the


positions ,
scores
, , necessary
accesories
, just like os
saving the machine state of a process
during a context switch
.
and when you "resume" a
game , you bring out the game, set the
board and continue seamlessly
up exactlylike
it was
,
playing ;
just Os
restering the machine state
, loading all

registers ,
stack , program counter etc. so the
process resumes
it left off
execution right where

what are the data structures thato s needs to track process


information ?
list
- maritims list of processes
process > a
-

process control block (PCB) >


-
information that of keeps to
(individual structure to each track each process.
process)
In order to return back the you need
game ,
a

well-organized game box that stares all the context information


the
resunce
game later. PCB fields uni os

This box
>
- ID
is the PCB * process ID (PID) Unique
-

execute
* program counter-next instruction to
↑ Register values Snapshot of CPU registers
-

CresS LUDO MONOPOLY stack heap data segment into


* , ,
cry pointers
-
mens
etc.
A process state-ready waiting running , ,
*
accounting info-CPU time used , execution stats
* 10 and file descriptors printers to opened files
-

,
devices used

A parent/child relationship-process hierarchy into

the PCB is a self-contained starage box that ensures the process


be resumed it left
can
exactly as was

Now
, imagine a
storage shelf where you keep CHESS CHESS
LUDO
all
your boxed
games when
you are not
playing
them .
Each box is clearly labeled and
carefully
placed in a slot .

This shelf is the Process list .

LUDO
structure and LUDO
- -
purpose
list maintained
* It's a
list/avraylinked
by the OS.

A each entry pointer to a PCB


is a

* the os consults this list to know what processes exist, their


current state , and where their
PCB is stared-
X- X

Reference
-
:
Chapter 4 of OSTEP -

You might also like