Unit 3.2 Process Control.ppt (Process Control and Scheduling)

AnilkumarBrahmane2 14 views 26 slides May 17, 2024
Slide 1
Slide 1 of 26
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26

About This Presentation

This is for learning purpose.


Slide Content

Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423 603
(An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Computer Engineering
(NBA Accredited)
Prof. A. V. Brahmane
Assistant Professor
E-mail : [email protected]
Contact No: 91301 91301 Ext :145, 9922827812
Subject-Operating System and Administration (CO2013)
Unit III-The Structure of Process, Process Control and
Process Scheduling

Content
•Process state and transitions,
•Layout of the system memory,
•Context of the process,
•Saving the context of the process,
•Manipulation the process address space,
•Sleep,
•Process creation,
•Signal,
•Process termination, Awaiting the process termination,
•Invoking other program, Process Scheduling
•Case Study -Access Control, Rootly Powers and Controlling Processes
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Process Control –Scheduling
•Therelationshipbetweenthesystemcallsandmemorymanagementalgorithms
isshowninthefollowingdiagram:
•Almost all calls usesleepandwakeupso its not shown in the figure.execalso interacts with the
file system algorithms
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Process Creation
•TheonlywaytocreateanewprocessinUNIXistousetheforksystemcall.The
processwhichcallsforkiscalledtheparentprocessandthenewlycreated
processiscalledthechildprocess.
•pid=fork();
•Onreturnoftheforksystemcall,thetwoprocesseshaveidenticaluser-level
contextexceptforthevalueofpid.pidfortheparentprocessistheprocessIDof
thechildprocess.Andpidforchildprocessis0.Theprocess0istheonlyprocess
whichisnotcreatedviafork.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Thestepsfollowedbythekernelforforkare:
•Itcreatesanewentryintheprocesstable.
•ItassignsauniqueIDtothenewlycreatedprocess.
•Itmakesalogicalcopyoftheregionsoftheparentprocess.Ifaregionscanbe
shared,onlyitsreferencecountisincrementedinsteadofmakingaphysicalcopy
oftheregion.
•Thereferencecountsoffiletableentriesandinodesoftheprocessareincreased.
•ItturnedthechildprocessIDtotheparentand0tothechild.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The algorithmfork
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Fork creating a New process context
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Signals
•Signalsinformprocessesoftheoccurrenceofasynchronousevents.Processes
maysendeachothersignalswiththekillsystemcall,orthekernelmaysend
signalsinternally.
•Thereare19signalsintheSystemV(Release2)UNIXsystemthatcanbe
classifiedasfollows:
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Signal Classifications
•Signalshavingtodowiththeterminationofaprocess,sendwhenaprocessexitsorwhenaprocessinvokes
thesignalsystemcallwiththedeathofchildparameter.
•Signalshavingtodowithprocessinducedexceptionssuchaswhenaprocessaccessesanaddressoutsideits
virtualaddressspace,whenitattemptstowritememorythatisread-only(suchasprogramtext),orwhenit
executesaprivilegedinstructionorforvarioushardwareerrors.
•Signalshavingtodowiththeunrecoverableconditionsduringasystemcall,suchasrunningoutofsystem
resourcesduringexecaftertheoriginaladdressspacehasbeenreleased
•Signalscausedbyanunexpectederrorconditionduringasystemcall,suchasmakinganonexistentsystem
call(theprocesspassedasystemcallnumberthatdoesnotcorrespondtoalegalsystemcall),writingapipe
thathasnoreaderprocesses,orusinganillegal"reference"valueforthelseeksystemcall.Itwouldbemore
consistenttoreturnanerroronsuchsystemcallsinsteadofgeneratingasignal,buttheuseofsignalsto
abortmisbehavingprocessesismorepragmatic.
•Signalsoriginatingfromaprocessinusermode,suchaswhenaprocesswishestoreceiveanalarmsignal
afteraperiodoftime,orwhenprocessessendarbitrarysignalstoeachotherwiththekillsystemcall.
•Signalsrelatedtoterminalinteractionsuchaswhenauserhandsupaterminal(orthe"carrier"signaldrops
onsuchalineforanyreason),orwhenauserpressesthe"break"or"delete"keysonaterminalkeyboard.
•Signalsfortracingexecutionofaprocess.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Checking and Handling Signals in the Process State Diagram
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The algorithmissig
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Handling Signals
•The handling of signal is done through the algorithmpsig,
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Types of Signals
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Process Groups
•Thesystemhastoidentifyprocessesby"groups"insomecases,forinstance,a
signalmightrelatetoalltheprocesseswhichareancestorsoftheloginshell.The
kernelusestheprocessgroupIDtoidentifygroupsofrelatedprocessesthat
shouldreceiveacommonsignalforcertainevents.ItsavesthegroupIDinthe
processtable.
•Thesetpgrpsystemcallinitializestheprocessgroupnumberofaprocessandsets
itequaltothevalueofitsprocessID.
•grp=setpgrp();
•wheregrpisthenewprocessgroupnumber.Achildretainstheprocessgroup
numberofitsparentduringfork.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Sending Signals from Processes
•Processesusethekillsystemcalltosendsignals.
•kill(pid,signum);
•wherepididentifiesthesetofprocessestoreceivethesignal,andsignumisthesignalnumber
beingsent.Thefollowinglistshowsthecorrespondencebetweenvaluesofpidandsetsof
processes.
•Ifpidisapositiveinteger,thekernelsendsthesignaltotheprocesswithprocessIDpid.
•Ifpidis0,thekernelsendsthesignaltoallprocessesinthesender'sprocessgroup.
•Ifpidis-1,thekernelsendsthesignaltoallprocesseswhoserealuserIDequalstheeffectiveuser
IDofthesender(realandeffectiveuserIDsarestudiedlater).Ifthesendingprocesshaseffective
userIDofsuperuser,thekernelsendsthesignaltoallprocessesexceptprocesses0and1.
•Ifpidisanegativeintegerbutnot-1,thekernelsendsthesignaltoallprocessesintheprocess
groupequaltotheabsolutevalueofpid.
•Inallcases,ifthesendingprocessdoesnothaveeffectiveuserIDofsuperuser,oritsrealor
effectiveuserIDdonotmatchtherealoreffectiveuserIDofthereceivingprocess,killfails.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Process Termination
•ProcessesontheUNIXsystemexitbyexecutingtheexitsystemcall.Whena
processexits,itentersthezombiestate,relinquishesallofitsresources,and
dismantlesitscontextexceptforitsprocesstableentry.
•exit(status);
•wherestatusistheexitcodereturnedtotheparent.Theprocessmay
callexitexplicitly,butthestartuproutineinCcallsexitafterthemainfunction
returns.Thekernelmaycallexitonreceivinganuncaughtsignal.Insuchcases,
thevalueofstatusisthesignalnumber.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The algorithm for exit
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Awaiting Process Termination
•Aprocesscansynchronizeitsexecutionwiththeterminationofachildprocessby
executingthewaitsystemcall.
•pid=wait(stat_addr);
•wherepidistheprocessIDofthezombiechild,andstat_addristheaddressin
userspaceofanintegerthatwillcontaintheexitstatuscodeofthechild.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The algorithm forwait
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Invoking Other Programs
•Theexecsystemcalloverlaystheaddressspaceofaprocesswiththecontentsof
anexecutablefile.
•execve(filename,argv,envp)
•wherefilenameisnameofthefilebeinginvoked,argvisapointertoarrayof
characterpointerswhichareargumentstotheprogramintheexecutablefile,
andenvpisapointertoarrayofcharacterpointerswhicharetheenvironmentof
theexecutedprogram.Thereareseverallibraryfunctionsthatcallexec,
likeexecl,execv,execle,andsoon.Allcallexecveeventually.Thecharacterstrings
intheenvparrayareoftheform,"name=value".Cprogramscanaccessthe
environmentvariablesbyaccessingtheglobalvariableenviron,initializedbythe
Cstartuproutine.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The algorithm forexec
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The User ID of a Process
•TherearetwouserIDassociatedwithaprocess,therealuserIDandtheeffective
userIDorsetuid(setuserID).TherealuserIDidentifiestheuserwhois
responsiblefortherunningprocess.TheeffectiveuserIDisusedtoassign
ownershipofnewlycreatedfiles,tocheckfileaccesspermissions,andtocheck
permissiontosendsignalstoprocessesviathekillsystemcall.Thekernelallowsa
processtochangeitseffectiveuserIDwhenitexecsasetuidprogramorwhenit
invokesthesetuidsystemcallexplicitly.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Asetuidprogramisanexecutablefilethathasthesetuidbitsetinitspermission
modefield.Whenaprocessexecsasetuidprogram,thekernelsetstheeffective
userIDfieldsintheprocesstableandu-areatotheownerIDofthefile.To
distinguishthetwofields,letuscallthefieldintheprocesstablethesaveduser
ID.
•setuid(uid);
•whereuidisthenewuserID,anditsresultdependsonthecurrentvalueofthe
effectiveuserID.IftheeffectiveuserIDofthecallingprocessissuperuser,the
kernelresetstherealandeffectiveuserIDfieldsintheprocesstableandu-area
touid.Ifitsnotthesuperuser,thekernelresetstheeffectiveuserIDintheu-area
touidifuidhasthevalueoftherealuserIDorifithasthevalueofthesaveduser
ID.Otherwise,thesystemcallreturnsanerror.Generally,aprocessinheritsits
realandeffectiveuserIDsfromitsparentduringtheforksystemcalland
maintainstheirvaluesacrossexecsystemcalls.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Changing the Size of a Process
•Aprocesscanincreaseordecreasethesizeofitsdataregionbyusing
thebrksystemcall.
•brk(endds);
•whereenddsbecomesthevalueofthehighestvirtualaddressofthedataregion
oftheprocess(calleditsbreakvalue).Alternatively,ausercancall
•oldendds=sbrk(increment);
•whereincrementchangesthecurrentbreakvaluebythespecifiednumberof
bytes,andoldenddsisthebreakvaluebeforethecall.sbrkisaClibraryroutine
thatcallsbrk.Thekernelchecksthatthenewprocesssizeislessthanthesystem
maximumandthatthenewdataregiondoesnotoverlappreviouslyassigned
virtualaddressspace.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Algorithm: brk
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Thank you …..
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Tags