Operating System
Lecture 03
Mohammad Ashraful Islam
Lecturer
Department of Computer Science and Engineering,
Jahangirnagar University
Process
A process is a program in execution which then forms the basis
of all computation.
The process is not as same as program code but a lot more than
it. A process is an 'active' entity as opposed to the program which
is considered to be a 'passive' entity.
Attributes held by the process include hardware state, memory,
CPU, etc.
Process in Memory
Process memoryis divided into four sections for efficient
working :
TheText sectionis made up of the compiled program
code, read in from non-volatile storage when the
program is launched.
TheData sectionis made up of the global and static
variables, allocated and initialized prior to executing
the main.
TheHeapis used for the dynamic memory allocation
and is managed via calls to new, delete, malloc, free,
etc.
TheStackis used for local variables. Space on the
stack is reserved for local variables when they are
declared.
Process States
New-The process is just being put together.
Running-Instructions being executed. This running process holds the
CPU.
Waiting-For an event (hardware, human, or another process.)
Ready-The process has all needed resources -waiting for CPU only.
Suspended-Another process has explicitly told this process to sleep. It
will be awakened when a process explicitly awakens it.
Terminated -The process is being torn apart.
Process Control Block
ThereisaProcessControlBlockforeachprocess,enclosing
alltheinformationabouttheprocess.Itisalsoknownasthe
taskcontrolblock.Itisadatastructure,whichcontainsthe
following:
ProcessState:Itcanberunning,waiting,etc.
ProcessIDandtheparentprocessID.
CPUregistersandProgramCounter.ProgramCounter
holdstheaddressofthenextinstructiontobeexecuted
forthatprocess.
CPUSchedulinginformation:Suchaspriority
informationandpointerstoschedulingqueues.
MemoryManagementinformation:Forexample,page
tablesorsegmenttables.
Accountinginformation:TheUserandkernelCPU
timeconsumed,accountnumbers,limits,etc.
I/OStatusinformation:Devicesallocated,openfile
tables,etc.
Process vs. Program
Process Program
The process is basically an instance of
the computer program that is being
executed.
A Program is basically a collection of
instructions that mainly performs a
specific task when executed by the
computer.
A process has ashorter lifetime. A Program has alonger lifetime.
A Process requires resources such as
memory, CPU, Input-Output devices.
A Program is stored by hard-disk and
does not require any resources.
A process has a dynamic instance of code
and data
A Program has static code and static
data.
Basically, a process is therunning
instanceof the code.
On the other hand, the program is
theexecutable code.
Process Scheduling
When there are two or more runnable processes
then it is decided by the Operating system which
one to run first then it is referred to as Process
Scheduling.
A scheduler is used to make decisions by using
some scheduling algorithm.
Good Scheduling Algorithm:
Response time should be minimum for the users.
The number of jobs processed per hour should be
maximum i.eGood scheduling algorithm should give
maximum throughput.
The utilization of the CPU should be 100%.
Each process should get a fair share of the CPU.
Process Scheduling
The act of determining which process is in the ready state, and 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 processesIN and OUTof CPU.
Process Scheduling Categories
Scheduling 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
favouranother process, pre-empting the currently executing process.
Scheduling Queues
In the first two cases, the process eventually switches from the waiting state to the
ready state, and is then put back in the ready queue. A process continues this cycle
until it terminates, at which time it is removed from all queues and has its PCB and
resources de-allocated.
Types of Schedulers
Therearethreetypesofschedulersavailable:
LongTermScheduler
ShortTermScheduler
MediumTermScheduler
Process Termination
Afteraprocesshasbeencreated,itstartsrunninganddoeswhatever
itsjobis.However,nothinglastsforever,notevenprocesses.Sooneror
laterthenewprocesswillterminate,usuallydueto
oneofthefollowingconditions:
1.Normalexit(voluntary).
2.Errorexit(voluntary).
3.Fatalerror(involuntary).
4.Killedbyanotherprocess(involuntary).
Process Queues
TheOperatingsystemmanagesvarioustypesofqueuesforeachofthe
processstates.
ThePCBrelatedtotheprocessisalsostoredinthequeueofthesame
state.
IftheProcessismovedfromonestatetoanotherstatethenitsPCBis
alsounlinkedfromthecorrespondingqueueandaddedtotheother
statequeueinwhichthetransitionismade.
Process Queues
There are the following queues maintained by the Operating system.
Job Queue: In starting, all the processes get stored in the job queue. It
is maintained in the secondary memory. The long term scheduler (Job
scheduler) picks some of the jobs and put them in the primary
memory.
Ready Queue: Ready queue is maintained in primary memory. The
short term scheduler picks the job from the ready queue and dispatch
to the CPU for the execution.
Waiting Queue: When the process needs some IO operation in order
to complete its execution, OS changes the state of the process from
running to waiting. The context (PCB) associated with the process gets
stored on the waiting queue which will be used by the Processor when
the process finishes the IO.
Various Times related to the Process
Exercise
First Determine Completion Time and then Calculate:
a)Waiting Time
b)Turn around Time
Various Times related to the Process
ArrivalTime:Thetimeatwhichtheprocessentersintothereadyqueueis
calledthearrivaltime.
BurstTime:ThetotalamountoftimerequiredbytheCPUtoexecutethe
wholeprocessiscalledtheBurstTime.Thisdoesnotincludethewaiting
time.Itisconfusingtocalculatetheexecutiontimeforaprocesseven
beforeexecutingithencetheschedulingproblemsbasedonthebursttime
cannotbeimplementedinreality.
CompletionTime:TheTimeatwhichtheprocessentersintothe
completionstateorthetimeatwhichtheprocesscompletesitsexecution,
iscalledcompletiontime.
Turnaroundtime:Thetotalamountoftimespentbytheprocessfromits
arrivaltoitscompletion,iscalledTurnaroundtime.
WaitingTime:TheTotalamountoftimeforwhichtheprocesswaitsfor
theCPUtobeassignediscalledwaitingtime.
ResponseTime:Thedifferencebetweenthearrivaltimeandthetimeat
whichtheprocessfirstgetstheCPUiscalledResponseTime.