صفحه 1:
Process Description and Control Chapter 3

صفحه 2:
Requirements of an Operating System ° Interleave the execution of multiple processes to maximize processor utilization while providing reasonable response time ° Allocate resources to processes ° Support interprocess communication and user creation of processes

صفحه 3:
Concepts Computer platform consists of a collection of hardware resources Computer applications are developed to perform some task Inefficient for applications to be written directly for a given hardware platform Operating system provides a convenient to use, feature rich, secure, and consistent interface for applications to use OS provides a uniform, abstract representation of resources that can be requested and accessed by application 3

صفحه 4:
Manage Execution of Applications ° Resources made available to multiple applications ° Processor is switched among multiptle application ° The processor and I/O devices can be used efficiently

صفحه 5:
Process ° A program in execution ° An instance of a program running on a computer ° The entity that can be assigned to and executed on a processor ° A unit of activity characterized by the execution of a sequence of instructions, a current state, and an associated set of system instructions

صفحه 6:
Process Elements ° Identifier ° State ° Priority ° Program counter ° Memory pointers ° Context data ° I/O status information ° Accounting information

صفحه 7:
Process Control Block ° Contains the process elements ° Created and manage by the operating system ° Allows support for multiple processes

صفحه 8:
Process Control Block Figure 3.1 Simplified Process Control Block.

صفحه 9:
Trace of Process ° Sequence of instruction that execute for a process ° Dispatcher switches the processor from one process to another

صفحه 10:
Example Execution ] Main Memory Program Counter 0 [ 00 100 Dispatcher 000 Process A 000 Process B ‏ل امم‎ Process Figure 3.2 Snapshot of Example Execution (Figure 3.4) ‘at Instruction Cycle 13 10

صفحه 11:
11 Trace of Processes 712000 12001 12002 12003 12004 12005 12006 12007 12008 12009 12010 12011 (©) Trace of Process 8000 8001 8002 3003 (by Trace of Process B 3000 5001 2002 5003 5004 5005 5006 5007 5008 5009 5010 S011 (@) Trace of Procoss A 5000 = Starting adkiress of program of Process A 8 of program of Process B Starting addkess of program of Process C 8000 = Starting adres: 1200 Figure 3.3 Traces of Processes of Figure 3.2

صفحه 12:
12 27 2 5001 2 3 0 45003 20 ‏و‎ 5004 30 & 5005, 31 2 3 ‏و‎ tol 34 ‏و‎ 33 19 03 36 110 4 37 12 05 38 13 $000 ‏و‎ ‏بر‎ 40 15 $002 16 3003 31 10 request 2 “a 18 1 a4 19 102 45 20 03 46 105 2b tod 47 12006 2 105 48 12007 23 12000 48 12008 2 L001 ‏ود‎ 12009 2% 12002 St 12010 26 12008, ‏و‎ 0۱ Timo out 100= Sang aces of cinatcher prose sd ara inciat neenin of pater process Satan thd sans cout astea see. ‘cua af conte show ade asrtion ig exeuted Figure 3.4 Combined Trace of Processes of Figure 32

صفحه 13:
Two-State Process Model * Process may be in one of two states ~ Running ~ Not-running Dispatch

صفحه 14:
Not-Running Process in a Queue 1) Queuing diagram

صفحه 15:
15 Process Creation ‘Table 31 Reasons for Process Creation ‘The operating system is provided with abatch job contol stream, usually on tape or disk. When the operating system is prepared to take on new work it will read the next sequcace of job control commands. Avvser at a terminal logs on to the system. ‘The operating system can create a process to perform a fiction on behalf of a weer program, withowt the user having to wait (e.g, 2 process to control printing) For purposes of modularity or to expfoit paralletism, a user program con dicate the creation of a number of processes [New batch ob linteractive logon Crested by OS to provide a service Spawned by existing process

صفحه 16:
16 Process Termination Table 3.2 Reasons for Process Termination ‘The process executes an OS service call to indicate that it has completed running ‘The process hs run longer than the specified total time limit, ‘There are ‏عه سدم د‎ of possibilities forthe type of time that is mented. These include total elapsed time (all clock ime”) amount of time spent executing, and inthe case of sn interactive process, the amouat of time since the user last provided any input. ‘The process requires more memory than the system can provide ‘The process tres to access 2 memory location that itis not allowed ‏هه و‎ ‘The process aiempls to use azesoures such asa file that it is not allowedta nse, or ities to use it in an improper fashion, such as ‘writing toa read-only file ‘The process tres a prohibited computation, such as division by zef0, or tries to stoce numbers larger than the hardware can accommodate [Normal comptetion [Time limit exceeded [Memory unavailable [Bounds violation [Protection error Arithmetic error

صفحه 17:
17 Process Termination ‘Table 3.2 Reasons for Process Termination ‘The process has waited longer than a specified maxim for @ Am ezor occurs during input or output, such as inability to find @ fle, Failure to read or write after a specified maximam number of tries (when, for exemple, a defective area js encountered ona tape), or invalid operation (such as reading from the line printer) ‘The process attempts to execute nonexistet instruction (often zesult of branching inte a data area and atfempting to execute the da. ‘The process attempt toe an instruction reserved for the ‘operating system. A piece of datas ofthe wrong type or is not initialized, terminated the process (for example, if 2 deadlockc exis) ‘When a pareat terminates, the operating system may automaticaly terminate all ofthe offspring ofthat parent A pmtene process pally asthe auto to tenn any fits opin [Time overran [20 ature fsvatid instruction [Privileged instruction [Date misuse JOperstor or OS intervention For some season, the operator or the operating system has JPacent termination [Parent request

صفحه 18:
Processes ° Not-running ~ ready to execute ° Blocked ~ waiting for I/O ° Dispatcher cannot just select the process that has been in the queue the longest because it may be blocked

صفحه 19:
A Five-State Model ° Running ° Ready ° Blocked ° New ° Exit

صفحه 20:
Five-State Process Model Figure 3.6 Vive-State Process Model

صفحه 21:
Process States Figure 37 Process States for Trace of Figure 34

صفحه 22:
Using Two Queues Ready Que cy f=] Rekase

صفحه 23:
Multiple Blocked Queues Figure 3.8 Queuing Model for Figure 36

صفحه 24:
Suspended Processes * Processor is faster than I/O so all processes could be waiting for I/O ° Swap these processes to disk to free up more memory * Blocked state becomes suspend state when swapped to disk ° Two new states ~ Blocked/Suspend ~ ReadySuspend

صفحه 25:
One Suspend State

صفحه 26:
Two Suspend States Figure 3.9 Process State Transition Diagram with Suspend States

صفحه 27:
27 A user may wish to suspend execution of «program for purposes of debugging or in conection with the use of A parent process may wish to suspend execution of a descendent to examine or modify the suspended process, oF Reasons for Process Suspension ‘Table 33 Reasons for Process Suspension ‘The operating system needs to release sufficient main memory to bring in process tht is eady to execute ‘The operating system may suspend a background or wility ‘process ora process thal is suspected of causing a problem, A process may be executed periodically (e.g. an sceouating or system monitoring prace:s) and may be suspended while waiting forthe aest tine interval. to coordinate the activity of various descendents Hatcractive user request Parent process request

صفحه 28:
Processes and Resources Figure 3.10 Processes and Resources (resource allocation at one snapshot in time)

صفحه 29:
Operating System Control Structures ° Information about the current status of each process and resource ° Tables are constructed for each entity the operating system manages

صفحه 30:
Memory Tables ° Allocation of main memory to processes ° Allocation of secondary memory to processes ° Protection attributes for access to shared memory regions ° Information needed to manage virtual memory

صفحه 31:
I/O Tables ° I/O device is available or assigned ° Status of I/O operation ° Location in main memory being used as the source or destination of the I/O transfer

صفحه 32:
File Tables ° Existence of files ° Location on secondary memory ° Current Status ° Attributes ¢ Sometimes this information is maintained by a file management system

صفحه 33:
Process Table ° Where process is located ° Attributes in the process control block ° Program ° Data ° Stack

صفحه 34:
34 Process Image Table 3.4 Typical Elomonts of a Process Image |User Data ‘The modifisble pat of the user space. May include program data, a user stack area, and programs that may be modified ser Program ‘The program to be executed. System Stack Each process has one or more lat-in-rst-cut (LIFO) system stacks associated with it A slack is used to store parameters and calling addresses for procedure and system calls. |Process Control Block ‘Data needed by the operating system to control the process (see Table 3 5)

صفحه 35:
Process Tage Process Process 1۳ [Process [Fite Tats Primary Process Table [Pieces 1 <a Process 3 > [Memory Tabs 0ج Memory Devices Fie) Figure 3.11 General Structure of Operating System Control Tables

صفحه 36:
Process Control Block ° Process identification ~ Identifiers * Numeric identifiers that may be stored with the process control block include Identifier of this process ~ Identifier of the process that created this process (parent process) User identifier 36

صفحه 37:
Process Control Block ° Processor State Information - User-Visible Registers * A user-visible register is one that may be referenced by means of the machine language that the processor executes while in user mode. Typically, there are from 8 to 32 of these registers, although some RISC implementations have over 100. 37

صفحه 38:
Process Control Block ° Processor State Information ~ Control and Status Registers These are a variety of processor registers that are employed to control the operation of the processor. These include * Program counter: Contains the address of the next instruction to be fetched * Condition codes: Result of the most recent arithmetic or logical operation (e.g., sign, zero, carry, equal, overflow) * Status information: Includes interrupt enabled/disabled flags, execution mode 38

صفحه 39:
Process Control Block ° Processor State Information ~ Stack Pointers * Each process has one or more last-in- first-out (LIFO) system stacks associated with it. A stack is used to store parameters and calling addresses for procedure and system calls. The stack pointer points to the top of the stack. 39

صفحه 40:
Process Control Block * Process Control Information Scheduling and State Information This is information that is needed by the operating system to perform its scheduling function. Typical items of defines the readiness of the process to be scheduled for execution (e.g., running, ready, waiting, halted). “Priority: One or more fields may be used to describe the scheduling priority of the process. In some systems, several values are required (e.g., default, current, highest- allowable) * Scheduling-related information: This will depend on the scheduling algorithm used. Examples are the amount of time that the process has been waiting and the amount of time that the process executed the last time it was running. *Event: Identity of event the process is awaiting before it can be resumed 40

صفحه 41:
Process Control Block * Process Control Information ~ Data Structuring * A process may be linked to other process in a queue, ring, or some other structure. For example, all processes in a waiting state for a particular priority level may be linked in a queue. A process may exhibit a parent-child (creator-created) relationship with another process. The process control block may contain pointers to other processes to support these structures. 41

صفحه 42:
Process Control Block * Process Control Information ~ Interprocess Communication * Various flags, signals, and messages may be associated with communication between two independent processes. Some or all of this information may be maintained in the process control block. ~ Process Privileges * Processes are granted privileges in terms of the memory that may be accessed and the types of instructions that may be executed. In addition, privileges may apply to the use of system utilities and services. 42

صفحه 43:
Process Control Block * Process Control Information ~ Memory Management ° This section may include pointers to segment and/or page tables that describe the virtual memory assigned to this process. ~ Resource Ownership and Utilization * Resources controlled by the process may be indicated, such as opened files. A history of utilization of the processor or other resources may also be included; this information may be needed by the scheduler. 43

صفحه 44:
Processor State Information ° Contents of processor registers - User-visible registers ~ Control and status registers ~ Stack pointers ° Program status word (PSW) - contains status information ~ Example: the EFLAGS register on Pentium machines

صفحه 45:
Pentium IT EFLAGS Register TTR] I ۳1 (۱ jr ۲۱۶۶| del lel fe ID = sceotifcation Dag DF = Direction fag ‘VIP = Viral inerapt pending TF Inierrpt enable Nag VIP = ‏امه سا‎ ag TF = Trap Dag AC = Alignmenteheck SF = Sipn ag VM = Virtual 8086 mode ‏ما مب - تلا‎ RF = Resume fag AF = Aula cay flag NT = Nested tsk tag PE = Parity Dag TOPL. = U0 privilege level CF = Cary fag OF = Overflow flag Figure 3.12 Pentium Il EFLAGS Register

صفحه 46:
Modes of Execution ° User mode ~ Less-privileged mode ~ User programs typically execute in this mode ° System mode, control mode, or kernel mode ~ More-privileged mode ~ Kernel of the operating system

صفحه 47:
Process Creation ° Assign a unique process identifier ° Allocate space for the process ° Initialize process control block ° Set up appropriate linkages ~ Ex: add new process to linked list used for scheduling queue ° Create of expand other data structures ~ Ex: maintain an accounting file

صفحه 48:
When to Switch a Process ° Clock interrupt ~ process has executed for the maximum allowable time slice ° I/O interrupt ° Memory fault ~ memory address is in virtual memory so it must be brought into main memory

صفحه 49:
When to Switch a Process ° Trap ~ error or exception occurred ~ may cause process to be moved to Exit state ° Supervisor call ~ such as file open

صفحه 50:
Change of Process State * Save context of processor including program counter and other registers * Update the process control block of the process that is currently in the Running state * Move process control block to appropriate queue - ready; blocked; ready/suspend * Select another process for execution 50

صفحه 51:
Change of Process State ° Update the process control block of the process selected ° Update memory-management data structures ° Restore context of the selected process

صفحه 52:
Execution of the Operating System * Non-process Kernel ~ Execute kernel outside of any process ~ Operating system code is executed as a separate entity that operates in privileged mode ° Execution Within User Processes ~ Operating system software within context of a user process ~ Process executes in privileged mode when executing operating system code 52

صفحه 53:
Pi) ‏او‎ ۲۷ [Pa Kernd (a) Separate kernel 3 vey fal ing Fos tine ress ‎jos,‏ ۷۱۲ لدم یط نا لا نا ‎Process Switehing Funetions‏ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎(c) OS functions execute as separate processes ‎Figure 3.15 Relationship Between Operating System and User Processes ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

صفحه 54:
Proce deatitication Processor Site Information Prvcess Comiroh Thorton ser Stack Private User Address Space (Programs, Data) Kernel Stack Figure 3.16 Process Image: Operating System Executes Within User Space

صفحه 55:
Execution of the Operating System ° Process-Based Operating System ~ Implement operating system as a collection of system processes ~ Useful in multi-processor or multi- computer environment

صفحه 56:
UNIX SVR4 Process Management * Most of the operating system executes within the environment of a user process ‎Py‏ ۶ ام ‎2 ‎2 ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎(0) 0S functions execute within user processes ‎ ‎ ‎ ‎

صفحه 57:
ov Process States ‘Table 39 UNIX Process States ‘Executing in user mode Executing in kernel mode. ‘Ready to run as soon as the kernel schedules it ‘Unable to execute until an event occurs: process is in main memory (@ biocied state) Process is ready to run, but the swapper must swap the process into ‘main memory before the kernel can schedule it to execute “The process is awaiting an event and has been swapped to secondary storage (a blocked state) Process is returning from kernel to user mode, but the kernel preempts it and does a process switch to schedule another process. Process is newly created and not vet ready to run Process no longer exists, but it leaves a record for its parent process t collect, UNIX ‘User Ranning Kernel Running Ready to Run, in Memory Asleep in Memory Ready to Run, Swapped Sleeping, Swapped Preempted Created Zombie

صفحه 58:
UNIX Process Image Table 3.10 UNIX Process Image TeerLevel Context Process Text Executable machine instructions of the program Process Data Data accessible by the propram ofthis process User Stack Contains the arguments, focal variables, ad pointers for functions executing in user mode Shared Memory ‘Memory stared with other processes, used for iterprocess Register Context Program Counter Adcess of nen instruction to be exectbed: may bein kernel oF tier memery space ofthis process Processor Stas Register Contains the hardware status at the time of preemption; costeats sand format are hardware dependent Stock: Pointer Points tothe top ofthe kernal or user stack: depending on the mode of operation a the time or preemption General-Purpose Registers Hardware dependent System Lovel Context Process Table Entry Defines state of a process: this information is alays accessible to the operating system Used) Area, Process control information that needs tobe accessed only in the context of the process Per Process Region Table Defines the mapping from virtual to physical adiesses; also contains a permission field that indicates the type of access allowed the process. read-only, read-wnite, ortead-execute Kernel Stok Contains the stack feeme of kernal prosedires as the process 58 000000

صفحه 59:
Figure 3.17 UNIX Process State Transition Diagram

Process Description and Control Chapter 3 1 Requirements of an Operating System • Interleave the execution of multiple processes to maximize processor utilization while providing reasonable response time • Allocate resources to processes • Support interprocess communication and user creation of processes 2 Concepts • Computer platform consists of a collection of hardware resources • Computer applications are developed to perform some task • Inefficient for applications to be written directly for a given hardware platform • Operating system provides a convenient to use, feature rich, secure, and consistent interface for applications to use • OS provides a uniform, abstract representation of resources that can be requested and accessed by application 3 Manage Execution of Applications • Resources made available to multiple applications • Processor is switched among multiptle application • The processor and I/O devices can be used efficiently 4 Process • A program in execution • An instance of a program running on a computer • The entity that can be assigned to and executed on a processor • A unit of activity characterized by the execution of a sequence of instructions, a current state, and an associated set of system instructions 5 Process Elements • Identifier • State • Priority • Program counter • Memory pointers • Context data • I/O status information • Accounting information 6 Process Control Block • Contains the process elements • Created and manage by the operating system • Allows support for multiple processes 7 Process Control Block 8 Trace of Process • Sequence of instruction that execute for a process • Dispatcher switches the processor from one process to another 9 Example Execution 10 Trace of Processes 11 12 Two-State Process Model • Process may be in one of two states – Running – Not-running 13 Not-Running Process in a Queue 14 Process Creation 15 Process Termination 16 Process Termination 17 Processes • Not-running – ready to execute • Blocked – waiting for I/O • Dispatcher cannot just select the process that has been in the queue the longest because it may be blocked 18 A Five-State Model • Running • Ready • Blocked • New • Exit 19 Five-State Process Model 20 Process States 21 Using Two Queues 22 Multiple Blocked Queues 23 Suspended Processes • Processor is faster than I/O so all processes could be waiting for I/O • Swap these processes to disk to free up more memory • Blocked state becomes suspend state when swapped to disk • Two new states – Blocked/Suspend – ReadySuspend 24 One Suspend State 25 Two Suspend States 26 Reasons for Process Suspension 27 Processes and Resources 28 Operating System Control Structures • Information about the current status of each process and resource • Tables are constructed for each entity the operating system manages 29 Memory Tables • Allocation of main memory to processes • Allocation of secondary memory to processes • Protection attributes for access to shared memory regions • Information needed to manage virtual memory 30 I/O Tables • I/O device is available or assigned • Status of I/O operation • Location in main memory being used as the source or destination of the I/O transfer 31 File Tables • Existence of files • Location on secondary memory • Current Status • Attributes • Sometimes this information is maintained by a file management system 32 Process Table • Where process is located • Attributes in the process control block • Program • Data • Stack 33 Process Image 34 35 Process Control Block • Process identification – Identifiers • Numeric identifiers that may be stored with the process control block include – Identifier of this process – Identifier of the process that created this process (parent process) – User identifier 36 Process Control Block • Processor State Information – User-Visible Registers • A user-visible register is one that may be referenced by means of the machine language that the processor executes while in user mode. Typically, there are from 8 to 32 of these registers, although some RISC implementations have over 100. 37 Process Control Block • Processor State Information – Control and Status Registers These are a variety of processor registers that are employed to control the operation of the processor. These include • Program counter: Contains the address of the next instruction to be fetched • Condition codes: Result of the most recent arithmetic or logical operation (e.g., sign, zero, carry, equal, overflow) • Status information: Includes interrupt enabled/disabled flags, execution mode 38 Process Control Block • Processor State Information – Stack Pointers • Each process has one or more last-infirst-out (LIFO) system stacks associated with it. A stack is used to store parameters and calling addresses for procedure and system calls. The stack pointer points to the top of the stack. 39 Process Control Block • Process Control Information – Scheduling and State Information This is information that is needed by the operating system to perform its scheduling function. Typical items of information: • Process state: defines the readiness of the process to be scheduled for execution (e.g., running, ready, waiting, halted). • Priority: One or more fields may be used to describe the scheduling priority of the process. In some systems, several values are required (e.g., default, current, highest-allowable) • Scheduling-related information: This will depend on the scheduling algorithm used. Examples are the amount of time that the process has been waiting and the amount of time that the process executed the last time it was running. • Event: Identity of event the process is awaiting before it can be resumed 40 Process Control Block • Process Control Information – Data Structuring • A process may be linked to other process in a queue, ring, or some other structure. For example, all processes in a waiting state for a particular priority level may be linked in a queue. A process may exhibit a parent-child (creator-created) relationship with another process. The process control block may contain pointers to other processes to support these structures. 41 Process Control Block • Process Control Information – Interprocess Communication • Various flags, signals, and messages may be associated with communication between two independent processes. Some or all of this information may be maintained in the process control block. – Process Privileges • Processes are granted privileges in terms of the memory that may be accessed and the types of instructions that may be executed. In addition, privileges may apply to the use of system utilities and services. 42 Process Control Block • Process Control Information – Memory Management • This section may include pointers to segment and/or page tables that describe the virtual memory assigned to this process. – Resource Ownership and Utilization • Resources controlled by the process may be indicated, such as opened files. A history of utilization of the processor or other resources may also be included; this information may be needed by the scheduler. 43 Processor State Information • Contents of processor registers – User-visible registers – Control and status registers – Stack pointers • Program status word (PSW) – contains status information – Example: the EFLAGS register on Pentium machines 44 Pentium II EFLAGS Register 45 Modes of Execution • User mode – Less-privileged mode – User programs typically execute in this mode • System mode, control mode, or kernel mode – More-privileged mode – Kernel of the operating system 46 Process Creation • • • • Assign a unique process identifier Allocate space for the process Initialize process control block Set up appropriate linkages – Ex: add new process to linked list used for scheduling queue • Create of expand other data structures – Ex: maintain an accounting file 47 When to Switch a Process • Clock interrupt – process has executed for the maximum allowable time slice • I/O interrupt • Memory fault – memory address is in virtual memory so it must be brought into main memory 48 When to Switch a Process • Trap – error or exception occurred – may cause process to be moved to Exit state • Supervisor call – such as file open 49 Change of Process State • Save context of processor including program counter and other registers • Update the process control block of the process that is currently in the Running state • Move process control block to appropriate queue – ready; blocked; ready/suspend • Select another process for execution 50 Change of Process State • Update the process control block of the process selected • Update memory-management data structures • Restore context of the selected process 51 Execution of the Operating System • Non-process Kernel – Execute kernel outside of any process – Operating system code is executed as a separate entity that operates in privileged mode • Execution Within User Processes – Operating system software within context of a user process – Process executes in privileged mode when executing operating system code 52 53 54 Execution of the Operating System • Process-Based Operating System – Implement operating system as a collection of system processes – Useful in multi-processor or multicomputer environment 55 UNIX SVR4 Process Management • Most of the operating system executes within the environment of a user process 56 UNIX Process States 57 UNIX Process Image 58 59

51,000 تومان