William Stallings Operating Systems Hoofdstuk 3 Beschrijving en besturing van processen UNIX Windows Cluster ANDROID Apple unix G..A. van Lierop LOGO LINUX www.themegallery.com
Operating Systems: Internals and Design Principles De voornaamste taak van een OS is het beheren van processen. Het OS moet systeembronnen toewijzen aan processen, deze in de gelegenheid te stellen om informatie te delen en uit te wisseelen, de bronnen van elk process afschermen en synchronisatie met elkaar mogelijk maken.
Een computer bestaat uit een verzameling hardware bronnen. Computer toepassingen zijn ontwikkeld om een bapaalde taak uit te voeren. It is inefficient for applications to be written directly for a given hardware platform The OS was developed to provide a convenient, feature-rich, secure, and consistent interface for applications to use We can think of the OS as providing a uniform, abstract representation of resources that can be requested and accessed by applications BV. OS bepaald als bronnen gedeeld of gebruikt worden. Het is abstract omdat de acties van de OS onzichtbaar zijn voor de gebruiker
OS Management van de uitvoering van toepassingen Bronnen beschikbaar gemaakt worden voor verschillende toepassingen. De fysieke processor schakelt tussen verschillende toepassingen. De processor en de I/O apparaten efficient kunnen worden gebruikt.
Process Elements Two essential elements of a process are: Program code which may be shared with other processes that are executing the same program A set of data associated with that code When the processor begins to execute the program code, we refer to this executing entity as a process
Tijdens de uitvoering van het programma, kan dit proces eenduidig gekenmerkt worden door een aantal elementen waaronder: identifier state priority program counter memory pointers context data I/O status information accounting information
Proces Besturings Block Wordt door een OS gecreerd en beheert Contains the process elements Makes it possible to interrupt a running process and later resume execution as if the interruption had not occurred Key tool that allows support for multiple processes, dus multiprogramming)
Process Process Implementation Process Control Blocks Active Context Process BYU CS 345 Chapter 3 - Processes 8
Process States Spoor/Trace Het gedrag van een individueel process kunnen we beschrijven aan de hand van de volgorde van instructies die voor dat proces wordt uitgevoerd. Het gedrag van de processor beschrijven door te tonen hoe de sporen van de diverse processen worden verwerven. Toedeler/Disp atcher Een klein programma dat de processor wisselend toewijst aan een ander proces
Process Execution
Traces of Processes of Figure 3.2 Each process runs to completion Figure 3.3
Combined Trace of Processes of Figure 3.2 Figure 3.4
Process Process Trace An instruction trace reveals the overhead required to multi-process. BYU CS 345 Chapter 3 - Processes 13
3.2.1 Procesmodel met 2 toestanden A process may be in one of two states: Actief/running Niet actief/not-running
Diagram wachtrij/queuing Diagram
3.2.2 Creeren en beeindigen van processen Table 3.1 Redenen voor het creeren van eenproces
3.2.2 Creeren van processen Process spawning Wanneer de OS een process creert op verzoek van een ander proces. Parent process is the original, creating, process Child process is the new process
Beeindiging van processen Er moet een manier zijn voor een process om aan te geven dat zijn taak is voltooid.hoe weet de OS wanneer een proces is voltooid? A batch job should include a HALT instruction or an explicit OS service call for termination Bij een gebruiker van een interactieve toepassing duidt de actie van de gebruiker aan dat een process is voltooid.
Table 3.2 Redenen voor het Beeindigen van processen Normal completion Time limit exceeded Memory unavailable Bounds violation Protection error Arithmetic error Time overrun I/O failure Invalid instruction Privileged instruction Data misuse Operator or OS intervention Parent termination Parent request The process executes an OS service call to indicate that it has completed running. The process has run longer than the specified total time limit. There are a number of possibilities for the type of time that is measured. These include total elapsed time ("wall clock time"), amount of time spent executing, and, in the case of an interactive process, the amount of time since the user last provided any input. The process requires more memory than the system can provide. The process tries to access a memory location that it is not allowed to access. The process attempts to use a resource such as a file that it is not allowed to use, or it tries to use it in an improper fashion, such as writing to a read-only file. The process tries a prohibited computation, such as division by zero, or tries to store numbers larger than the hardware can accommodate. The process has waited longer than a specified maximum for a certain event to occur. An error occurs during input or output, such as inability to find a file, failure to read or write after a specified maximum number of tries (when, for example, a defective area is encountered on a tape), or invalid operation (such as reading from the line printer). The process attempts to execute a nonexistent instruction (often a result of branching into a data area and attempting to execute the data). The process attempts to use an instruction reserved for the operating system. A piece of data is of the wrong type or is not initialized. For some reason, the operator or the operating system has terminated the process (e.g., if a deadlock exists). When a parent terminates, the operating system may automatically terminate all of the offspring of that parent. A parent process typically has the authority to terminate any of its offspring.
3.2.3 Procesmodel met 5 toestanden
Procestoestand bij het spoor van figuur 3.4
Using Two Queues
Multiple Blocked Queues
De noodzaak van Swapping involves moving part or all of a process from main memory to disk when none of the processes in main memory is in the Ready state, the OS swaps one of the blocked processes out on to disk into a suspend queue to make room for a new process, or a previously suspended process that is now ready to execute Commonly used in systems that had no virtual memory; less likely to be used with virtual memory since process size can be controlled through the paging mechanism.
Met 1 toestand opgeschort
Met 2 toestanden opgeschort
Andere toepassingen van opschorten 1. Het process is niet onmiddelijk beschikbaar voor uitvoering 2.The process may or may not be waiting on an event 3.Het process werd in de toestand opgeschort geplaatst door het process zelf of door een ander process om de uitvoering van het process te verhinderen. 4. The process may not be removed from this state until the agent explicitly orders the removal
Redenen voor het opschorten van processen Table 3.3 Reasons for Process Suspension
3.3 Beschrijven van processen What does the OS need to know to manage processes & resources?
3.3.1 Beheerstucturen in het besturingssysteem
3.3.1 Beschrijven van processen Wordt gebruikt voor het bijhouden van het hoofdgeheugen en het secundaire geheugen. Processen worden ondergebracht in het secundaire geheugen met een eenvoudige vorm van swapping. Must include: Toewijzen van hoofdgeheugen aan processen Toewijzing van secundair geheugen aan processen Bescherming attributen van blocks van hoofd-of virtueel geheugen Alle info die nodig is voor het beheren van het virtuele geheugen
3.3 Beschrijven van processen Used by the OS to manage the I/O devices and channels of the computer system At any given time, an I/O device may be available or assigned to a particular process If an I/O operation is in progress, the OS needs to know: the status of the I/O operation the location in main memory being used as the source or destination of the I/O transfer
3.3.1 Beschrijven van processen Een groot deel of zelfs alle informatie wordt bijgehouden en gebruikt door het filemanagament systeem. Bij andere besturingssystemen worden veel details van het bestandbeheer aan een OS overgelaten These tables provide information about: existence of files location on secondary memory current status other attributes
3.3.1 Beschrijven van processen Wordt bijgehouden door het beheren van processen. Proces tabellen moeten direct of indirect verwijzen naar geheugen, I/O en bestand tabellen e.g., pointers from each individual process entry to its data in the other three sets of tables. The tables themselves must be accessible by the OS and therefore are subject to memory management Processes are represented by a process image
Process Components Process Attributes 3.3.2 Beheerstructuren van processen Proces Locatie Proces Attributen Een process bevat ten minste 1 uit te voeren programma of verzameling programma s. Een process zal daarom op zijn minst bestaan uit voldoende geheugen voor het opslaan voor programma s en gegevens van een process. Bij de uitvoering van een programma wordt vaak een Stack gebruikt voor het bijhouden van procedure aanroepen en de parameters die worden doorgegeven tussen procedures. Voor elk process bestaat een aantal attributen dat door het besturingssysteem wordt gebruikt voor de besturing ervan. Deze verzameling attributen wordt een Process Control Block (PCB)genoemd. De verzameling die bestaat uit het programma, de gebruikers gegevens, de stack en de attributen het process beeld (process image)
3.3.2 Beheerstructuren van processen Processattributen Een geavanceerd multiprogrammeringsysteem heeft veel informatie over processen nodig. Deze info is in de PCB terug te vinden. We kunnen Informatie in het PCB groeperen tot drie algemene categorieen: Procesidentificatie Processortoestandinformatie processorbesturingsinformatie
Each process is assigned a unique numeric identifier otherwise there must be a mapping that allows the OS to locate the appropriate tables based on the process identifier Many of the tables controlled by the OS may use process identifiers to cross-reference process tables Memory tables may be organized to provide a map of main memory with an indication of which process is assigned to each region similar references will appear in I/O and file tables When processes communicate with one another, the process identifier informs the OS of the destination of a particular communication When processes are allowed to create other processes, identifiers indicate the parent and descendents of each process
Processortoestandinformatie Bestaat uit de inhoud van de processor registers user-visible registers control and status registers stack pointers Program status word (PSW) contains condition codes plus other status information EFLAGS register is an example of a PSW used by any OS running on an x86 processor
X86 EFLAGS Register
Processorbesturingsinformatie/ Dit is de aanvullende informatie die het besturingssyseem nodig heft voor het beheren en coordineren van de diverse actieve processen Forms the 3 rd part of the PCB (along with process ID and processor state information)
Process List Structures
The most important data structure in an OS contains all of the information about a process that is needed by the OS blocks are read and/or modified by virtually every module in the OS defines the state of the OS Difficulty is not access, but protection a bug in a single routine could damage process control blocks, which could destroy the system s ability to manage the affected processes a design change in the structure or semantics of the process control block could affect a number of modules in the OS
3.4.2 Uitvoeringsmodi User Mode Minder gepriviligieerde modes van de processor Gebruikersprogramma worden in deze modus uitgevoerd. System Mode(control mode of kenrel modus) more-privileged mode van de processor also referred to as control mode or kernel mode Verbonden met het besturingssysteem kernel of the operating system
Table 3.7 Standaardfuncties van de kernel van een besturingssysteem
3.4.2 Creeren van processen Once the OS decides to create a new process it: wijst een unieke procesidentificatie toe aan het nieuwe proces Wijst ruimte toe aan het proces Het PCB moet worden geinitialiseerd De juiste koppelingen worden ingesteld Soms moeten andere gegevensstructuren worden gemaakt of uitgebreid
3.4.3 Wisselen van processen Een proceswisseling kan steeds optreden wanneer het besturingssysteem de bestruring heeft overgenomen van het process dat op dit moment wordt uitgevoerd
Interrupt Oorzaak is extern aan de uitvoering van het huidig proces I/O interrupt geheugen fout clock interrupt Time slice the maximum amount of time that a process can execute before being interrupted 3.4.3 Wisselen van processen System Interrupts Trap Hangt samen met een fout of uitzonderingsconditie die wordt gegenereerd binnen het actieve proces zelf, aan de huidige instructie. OS determines if the condition is fatal moved to the Exit state and a process switch occurs action will depend on the nature of the error
If no interrupts are pending the processor: If an interrupt is pending the processor: proceeds to the fetch stage and fetches the next instruction of the current program in the current process sets the program counter to the starting address of an interrupt handler program switches from user mode to kernel mode so that the interrupt processing code may include privileged instructions
A mode switch is distinct from a process switch. A mode switch can take place without changing the state of the executing process However, while processing a mode switch the OS may decide a process switch is needed; e.g., if the mode switch was caused by a timer interrupt or a process request for I/O
The steps in a full process switch are: save the context of the processor update the process control block of the process currently in the Running state move the process control block of this process to the appropriate queue If the currently running process is to be moved to another state (Ready, Blocked, etc.), then the OS must make substantial changes in its environment select another process for execution restore the context of the processor to that which existed at the time the selected process was last switched out update memory management data structures update the process control block of the process selected
Execution of the Operating System
Execution Within User Processes
3.5 Procesbeheer in Unix SVR4 Uses the model where most of the OS executes within the environment of a user process Two process categories: system processes and user processes System processes run in kernel mode executes operating system code to perform administrative and housekeeping functions independent of any specific user process. User Processes operate in user mode to execute user programs and utilities operate in kernel mode to execute instructions that belong to the kernel enter kernel mode by issuing a system call, when an exception is generated, or when an interrupt occurs
UNIX Process States
UNIX Process State Transition Diagram
A Unix Process
Table 3.11 UNIX Process Table Entry
Table 3.12 UNIX U Area
Process creation is by means of the kernel system call, fork( ) This causes the OS, in Kernel Mode, to: 1 2 3 4 Allocate a slot in the process table for the new process Assign a unique process ID to the child process Make a copy of the process image of the parent, with the exception of any shared memory Increments counters for any files owned by the parent, to reflect that an additional process now also owns those files 5 6 Assigns the child process to the Ready to Run state Returns the ID number of the child to the parent process, and a 0 value to the child process
After creating the process the Kernel can do one of the following, as part of the dispatcher routine: stay in the parent process transfer control to the child process transfer control to another process
Summary The most fundamental concept in a modern OS is the process The principal function of the OS is to create, manage, and terminate processes Process control block contains all of the information that is required for the OS to manage the process, including its current state, resources allocated to it, priority, and other relevant data The most important states are Ready, Running and Blocked The running process is the one that is currently being executed by the processor A blocked process is waiting for the completion of some event A running process is interrupted either by an interrupt or by executing a supervisor call to the OS