operating systems: lesson 3: introduction to process...
TRANSCRIPT
![Page 1: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/1.jpg)
OperatingSystems
OPERATING SYSTEMS:
Lesson 3:Introduction to Process Management
1
Jesús Carretero PérezDavid Expósito SinghJosé Daniel García SánchezFrancisco Javier García BlasFlorin Isaila
![Page 2: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/2.jpg)
OperatingSystems
Contents
¨Processconcept.¨Basiclifecycleofaprocess.¨Processinformation¨Multitasking.¨Contextswitch.¨Generatinganexecutable.
2
![Page 3: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/3.jpg)
OperatingSystems
Process
• Process:Programinexecution.– Eachexecutionofaprogramleadstoaprocess.– Processistheunitofmanagementforoperatingsystem
• Aprocessconsistsof:– Programtext:Instructions.– Setofdataassociatedtoprogramexecution.
3
![Page 4: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/4.jpg)
OperatingSystems
Programexecution
ExecutableProgram
A
Mai
n M
emor
y
Process A1
Process A2
4
![Page 5: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/5.jpg)
OperatingSystems
Memoryrepresentation
• Aprocessneedsmemoryforinstructionsanddata.
• Differentinstancesofaprogramneedindependentareasfordata.
text
data
heap
stack
5
![Page 6: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/6.jpg)
OperatingSystems
Contents
¨Processconcept.¨Basiclifecycleofaprocess.¨Processinformation¨Multitasking.¨Contextswitch.¨Generatinganexecutable.
6
![Page 7: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/7.jpg)
OperatingSystems
Basiclifecycleofprocess
Running
BlockedReady
Wait an event
End of event blocking
Time-slicefinished
Activation
As many asprocessors
7
New processes
Fin
![Page 8: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/8.jpg)
OperatingSystems
Simplifiedqueuingmodel:Singleprocessor
Processor
Ev 1
New processes Finished processes
Ev 2
Ev 3…
End of time-slice
8
![Page 9: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/9.jpg)
OperatingSystems
Simplifiedqueuingmodel:Multipleprocessors
Processor
Ev 1
New processes
Ev 2
Ev 3
…
End of time-slice
FinishedProcesses
9
![Page 10: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/10.jpg)
OperatingSystems
Contents
¨Processconcept.¨Basiclifecycleofaprocess.¨Processinformation¨Multitasking.¨Contextswitch.¨Generatinganexecutable.
10
![Page 11: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/11.jpg)
OperatingSystems
Processinformation
• Alltheinformationallowingtheprocesscorrectexecution.
• Threecategories:– Informationstoredintheprocessor.– Informationstoredinmemory.– Additionalinformationmanagedbyoperatingsystem.
11
![Page 12: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/12.jpg)
OperatingSystems
Processorstate
¨Processorstateincludesvaluesofprocessorregisters.¤Registersaccessibleinusermode.
¤ Generalregisters: Registerfile.¤ Programcounter.¤ Stackpointer.¤ Userpartinstatusregister.
¤Registersaccessibleinprivilegedmode:n Privilegedpartfromstatusregister.nMemorymanagement registers(e.g.PTBR).
¨Contextswitch:¨ Saveprocessorstateforoutgoingprocess.¨ Restoreprocessorstateforincomingprocess.
12
![Page 13: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/13.jpg)
OperatingSystems
Memoryimageofaprocess
¨Memoryimageconsistsofthememoryspacesthataprocessisauthorizedtouse.
¨Ifaprocessgeneratesanaddressoutoftheaddressspace,hardwaregeneratesatrap.
¨Dependingonspecificcomputer,memoryimagemaybereferredtovirtualmemoryorphysicalmemory.
13
![Page 14: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/14.jpg)
OperatingSystems
Memoryimagemodels:Singleregion
• Processwithasinglefixedsizeregion.– Usedinsystemswithoutvirtualmemory.
• Processwithasinglevariablesizedregion.– Systemswithoutvirtualmemory:
• Needreservespace" Memorywaste.
– Systemswithvirtualmemory:• Virtualreservespace" Feasiblebutlessflexiblethanmultipleregion.
• Notused.
14
![Page 15: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/15.jpg)
OperatingSystems
Memoryimagemodels:Multipleregions
• Processwithfixednumberofregionsofvariablesize.– Prefixedregions(text,data,stack).– Eachregionmaygrow.– Withvirtualmemory,theholebetweenstackandheapdoesnotconsumeresources.
text
data
stack
15
![Page 16: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/16.jpg)
OperatingSystems
Memoryimagemodels:Multipleregions
• Processwithvariablenumberofregionsofvariablesize.– More advancedoption(usedincurrentversionsinWindowsandUNIX).
– Processstructuredasanumberofregions.– Veryflexible:
• Sharedregions.• Regionsmaydifferinpermissions.
16
![Page 17: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/17.jpg)
OperatingSystems
Operatingsysteminformation
17
• Operatingsystemkeepsadditionalinformationonprocesses.
• Operatingsystemkeepsinformationinatable:ProcessTable.
• ProcessControlBlock (PCB):Eachentryintablekeepsinformationaboutoneprocess.
• AlmostallinformationaboutprocessstoredinPCB.nSomeinformationelementskeptoutsideduetoimplementationreasons.
![Page 18: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/18.jpg)
OperatingSystems
Example:•Process identification.•Parent process identification.•User information.
ContenidosdelBCP
• Identificationinformation.
• Processorstate.• Processcontrolinformation.
18
On process start:•Initial values for processor state.After context switch:•Copy state values to processor.
Scheduling and state information:•Process state.•Waited event (if blocked).•Process priority.•Scheduling information.Allocated regions description.•Per region information.Allocated resources:•Open files.•Used communication ports.•Timers.Pointers for structuring process queues (or rings).Information for inter process communication.
![Page 19: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/19.jpg)
OperatingSystems
InformationoutofPCB
• NotalltheinformationreferredtoaprocessisstoredinitsPCB.
• Decisiontakeninfunctionof:– Efficiency.
• Tablesshouldhaveaprefixedsizeandalwaysbeinmemory.• Sizeneedstobeoptimized.
– InformationSharing.• IfdataneedstobeshareditcannotbeinthePCB.• Pointersareusedtopointtootherstructures (tables)allowingforinformation sharing.
– Openfiles.– Memorypages.
19
![Page 20: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/20.jpg)
OperatingSystems
PageTable
• PlacedoutsidePCB.
• Describesprocessmemoryimage.• PCBcontainspointertopagetable.• Reasons:
– Variablesize.– MemorysharingamongprocessesrequiresittobeexternaltoPCB.
20
![Page 21: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/21.jpg)
OperatingSystems
Filepositionpointers
• PlacedoutsidePCB.
• Ifaddedtoopenfilestable(inPCB)cannotbeshared.
• Ifassociatedtoi-nodeisalwaysshared.
• StoredinacommonstructureformultipleprocessesandanewoneallocatedwithOPENservice.
21
![Page 22: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/22.jpg)
OperatingSystems
Example:Runningacommand
#include <sys/types.h>
#include <stdio.h>int main(int argc, char** argv) {pid_t pid;pid = fork();switch (pid) {
case -1: /* error */exit(-1);
case 0: /* proceso hijo */if (execvp(argv[1], &argv[1])<0) { perror(“error”); }break;
default:printf(“Proceso padre”);
}
return 0;}
prog cat f1
22
![Page 23: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/23.jpg)
OperatingSystems
Forkservice
• pid_t fork(void);
¨ Duplicatesprocessinvokingthecall.¨ Parentprocessandchildprocessgoonrunningthesameprogram.¨ Childprocessinheritsopenfilesfromparentprocess.
¨ Openfiledescriptorsarecopied.¨ Pendingalarmsaredeactivated.
• Returns:– -1onerror.– Inparentprocess:childprocessdescriptor.– Inchildprocess:0.
23
![Page 24: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/24.jpg)
OperatingSystems
Forkservice
24
Process A
Process A’
FORK
![Page 25: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/25.jpg)
OperatingSystems
Execservice
• Singleservicewithmultiple libraryfunctions.int execl(const char *path, const char *arg, ...);int execv(const char* path, char* const argv[]);int execve(const char* path, char* const argv[], char* const envp[]);int execvp(const char *file, char *const argv[])
• Changescurrentprocessimage.– path:pathtoexecutable file.– file:LooksfortheexecutablefileinalldirectoriesspecifiedbyPATH.
• Description:– Returns-1onerror,otherwiseitdoesnotreturn.– Thesameprocessrunsanotherprogram.– Openfilesremainopen.– Signalswithdefaultactionremaindefaulted,signalswithhandlertakedefault
action.
25
![Page 26: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/26.jpg)
OperatingSystems
Execservice
26
Process A
Proceso A’
EXEC
Process B
![Page 27: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/27.jpg)
OperatingSystems
Exitservice
• Finalizesprocessexecution.
void exit(status);
• Allopenfilesdescriptorsareclosed.• Allprocessresourcesarereleased.• PCB (ProcessControlBlock)isreleased.
27
![Page 28: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/28.jpg)
OperatingSystems
Contents
¨Processconcept.¨Basiclifecycleofaprocess.¨Processinformation¨Multitasking.¨Contextswitch.¨Generatinganexecutable.
28
![Page 29: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/29.jpg)
OperatingSystems
Operatingsystemtypes
Operating Systems
Multiprocess(several processes
running)
Multiuser(several users
at a time)
Monouser(a single user
at a time)
Monoprocess(single process)
Monouser(a single user at a
time)
29
![Page 30: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/30.jpg)
OperatingSystems
Principlesofmultitasking
• RealparallelismbetweenI/OandCPU(DMA).• ProcessalternatebetweenI/Oandprocessingphases.
• Severalprocessesstoredinmemory.
30
![Page 31: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/31.jpg)
OperatingSystems
Advantagesofmultitasking
• Easesprogramming,dividingaprograminmultipleprocesses(modularity).
• Allowssimultaneousinteractiveserviceofmultipleusersinanefficientway.
• TakesadvantageoftimesaprocessspendswaitingforanI/Ooperationtobecompleted.
• IncreasesutilizationofCPU.
31
![Page 32: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/32.jpg)
OperatingSystems
Multiprogrammingdegree
• Multiprogrammingdegree:Numberofactiveprocesses.
• Mainmemoryneeds:Systemwithoutvirtualmemory.
32
100%
Multiprogramming degree
% C
PU u
tiliz
atio
n
![Page 33: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/33.jpg)
OperatingSystems
Multiprogramming:CPUuse
1 process
2 processes
Execution
I/O
33
![Page 34: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/34.jpg)
OperatingSystems
Multiprogrammingandvirtualmemory
• Systemswithvirtualmemory:– Divideaddressingspaceofprocessesinpages.– Dividephysicalmemoryaddressingspaceinmainmemoryinpageframes.
• Atagiventime,eachprocesshasacertainnumberofitspagesinmainmemory(residentset).
34
![Page 35: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/35.jpg)
OperatingSystems
Memoryneeds:Virtualmemorysystem
Page
fram
es p
er p
roce
ss
Multiprogramming degree
35
![Page 36: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/36.jpg)
OperatingSystems
Performance:Smallphysicalmemory
¨Whenmultiprogrammingdegreeincreases:¨ Residentsetsize
decreasesforeachprocess.
¨TrashinghappensbeforeachievingahighCPUutilizationpercentage.
¨Solution:Addmoremainmemory.
100%
Multiprogramming degree
% C
PU u
tiliz
atio
n
36
![Page 37: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/37.jpg)
OperatingSystems
Performance:Largephysicalmemory
• Whenmultiprogrammingdegreeincreases:– Residentsetsizedecreasesfor
eachprocess.
• HighCPUutilizationpercentageisachievedwithlessprocessesthatfitinmemory.
• Solution:Improveprocessororaddmoreprocessors.
100%
Multiprogramming degree
% C
PU u
tiliz
atio
n
37
![Page 38: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/38.jpg)
OperatingSystems
Contents
¨Processconcept.¨Basiclifecycleofaprocess.¨Processinformation¨Multitasking.¨Contextswitch.¨Generatinganexecutable.
38
![Page 39: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/39.jpg)
OperatingSystems
Contextswitching
• Whenoperatingsystemassignsprocessortoanewprocess.
• Actions:– SaveprocessstateinPCBforprocessinexecution.– Restorestateofnewprocessinprocessor.
39
![Page 40: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/40.jpg)
OperatingSystems
Contextswitch
Save state in PCB0
Restore state from PCB1
Save state in PCB1
Restore state from PCB0
40
![Page 41: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/41.jpg)
OperatingSystems
Contextswitchingtypes
¨Voluntarycontextswitch:¤ Processperformscalltooperatingsystem(orgeneratesexceptionlike
pagefault)implyingwaitingforanevent.¤Running" Blocked.¤ Examples:readingfromterminal,pagefault.¤Reason⇒ Processoruseefficiency.
¨ Involuntarycontextswitch:¤OSappropriatesCPU.¤Running" Ready.¤ Examples:timesliceellapsed orprocessmovesfromblockedtoready
andhashigherpriority.¤Reason⇒ Processorusesharing
41
![Page 42: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/42.jpg)
OperatingSystems
Contents
¨Processconcept.¨Basiclifecycleofaprocess.¨Processinformation¨Multitasking.¨Contextswitch.¨Generatinganexecutable.
42
![Page 43: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/43.jpg)
OperatingSystems
Executablegeneration
Linker (ld)
Compiler
a.c
a.o
Compiler
b.c
b.o
p
Relocatable object files separately generated
Executable object file (contains code and data for all defined functions in a.c and b.c).
43
![Page 44: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/44.jpg)
OperatingSystems
LinkEditor(linker)
n Combinesobjectfiles:¨ Mergesseveralrelocatableobjectfiles(.o)inasingle
executableobjectfile:inputforloader.
n Resolvesexternalreferences:¨ Referencestosymbolsdefinedinotherobjectfile.
n Relocatessymbols:n Fromrelativepositionsin.otoabsolutepositionsin
executable:adjustrefstothesenewpositions.n Symbols:refstofunctionsanddata.
44
![Page 45: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/45.jpg)
OperatingSystems
Ejemplo:FormatoELF
n ELF:ExecutableandLinkableFormat
¨ formatobinarioestándarparaficherosobjeto¨ originaldeSystemVà BSD,Linux,Solaris¨ formatounificadopara:
n ficherosobjetoreubicablesn ficherosobjetoejecutablesn ficherosobjetocompartidos
45
![Page 46: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/46.jpg)
OperatingSystems
ELFformat
ELF header
Program header table(required for executables)
.text section
.data section
.bss section
.symtab
.rel.txt
.rel.data
.debug
Section header table(required for relocatables)
0
Code
“block started bysymbol” Non-
initialized staticdata
Type (.o, .exe, .so, etc); machine; Big /Little end; etc
Symbol table
Relocationinfo
Iinitialized staticdata
46
![Page 47: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/47.jpg)
OperatingSystems
Executableload
ELF header
Program header table(required for executables)
.text section
.data section
.bss section
.symtab
.rel.text
.rel.data
.debug
Section header table(required for relocatables)
0
.text segment(r/o)
.data segment(initialized r/w)
.bss segment(uninitialized r/w)
Process image
0x08048494
init and shared libsegments
0x080483e0
Virtual addr
0x0804a010
0x0804a3b0
MEMORYDISK
47
![Page 48: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/48.jpg)
OperatingSystems
Staticlibrary
Compiler
a.c
a.o
Compiler
b.c
b.o libc.aStatic library: file with contatenation of relocatableobject files.
Executable object file: includes code from functions in libc used in the program.
Linker (ld)
p
48
![Page 49: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/49.jpg)
OperatingSystems
Staticanddynamiclibraries
n Drawbacksofstaticlibraries:¨ Codepotentiallyduplicatedinexecutables:
¨ Disk(filesystem).¨ Virtualmemoryspaceinprocesses.
¨ Bugsinlibraries" newversion" needtorelink
n Solution:dynamiclibraries(*.so) (dynamiclinklibraries,DLLs):n Componentsloadedinmemoryandexecutedatruntime.n Functionsfromlibrariesmaybesharedamongmultipleprocesses.
49
![Page 50: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/50.jpg)
OperatingSystems
Dynamiclibraries
Functions from libc.so and invoked from a.c and b.c are loaded and linked.Potentially shared among multiple processes.
Shared library
Compiler
a.c
a.o
Compilerb.c
b.o
libc.so
Linker (ld)
p
Cargador / Enlazador dinámico
(ld-linux.so)
Executable in memory P’50
![Page 51: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/51.jpg)
OperatingSystems
Reminder
¨ Differencebetweenprogramandprocess.¨ Aprocessisaporgram inexecution.
¨ Operatingsystemmanagesrunningprocesses(processlifecycle).¨ Processinformationconsistingof:processstate,memoryimage
andPCB.¨Multitaskingallowsabetteruseofcomputerresources.¨ Contextswitchingintroducesasmalloverhead.¨ Staticlibrariesarelinkedatcompiletimewhiledynamiclibraries
arelinkedatprocesscreationtime.¨ Processcreationimpliescreationofitsmemoryimageandthe
allocationofaPCB.
51
![Page 52: OPERATING SYSTEMS: Lesson 3: Introduction to Process ...ocw.uc3m.es/ingenieria-informatica/operating...Operating Systems Process • Process: Program in execution. – Each execution](https://reader030.vdocuments.us/reader030/viewer/2022040922/5e9b5a7b8ac30050e75c5592/html5/thumbnails/52.jpg)
OperatingSystems
OPERATING SYSTEMS:
Lesson 3:Introduction to Process Management
52
Jesús Carretero PérezDavid Expósito SinghJosé Daniel García SánchezFrancisco Javier García BlasFlorin Isaila