Download presentation
Presentation is loading. Please wait.
Published byJanel Pierce Modified over 8 years ago
1
CSNB224 – AAG 2007 Process Description and Control Chapter 3
2
CSNB224 – AAG 2007 Process Description and Control All multiprogramming OS are build around the concept of processes A process is sometimes called a task
3
CSNB224 – AAG 2007 Major Requirements of an OS OS must interleave the execution of several processes to maximize processor usage while providing reasonable response time OS must allocate resources to processes while avoiding deadlock OS must support inter process communication and user creation of processes
4
CSNB224 – AAG 2007 Process A process is created for a program to be executed. Also called a task Execution of an individual program Involves a sequence of instruction within that program. Can characterize the behavior of a process by listing the sequence (trace of the process) of instructions that execute for that process.
5
CSNB224 – AAG 2007 Process Trace Figure 3.1 shows a memory layout of three processes. Assume no used of virtual memory. All of the process are fully loaded in the main memory. There is dispatcher program that switches the processor from one process to another.
7
CSNB224 – AAG 2007 Process Trace.. Figure 3.2 shows the trace of three processes during early part of their execution. First 12 instructions executed in processes A and C are shown. Process B executes four instructions and assume that the fourth instruction invokes and I/O operation for which the process must wait.
9
CSNB224 – AAG 2007 Process Trace.. Figure 3.3 shows traces from processor’s point of view. It shows the interleaved traces resulting from the 52 instruction cycles. Assume OS allowed a process to continue execution for a maximum of 6 instruction cycles, then the process will be interrupted, thus its prevent single process from monopolizing processor time.
10
CSNB224 – AAG 2007 Process Trace.. The first 6 instructions of process A are executed, followed by a time-out and execution of some code in the dispatcher, which execute 6 instructions before turning control to process B. After 4 instructions are executed, process B request and I/O action for which it must wait.
11
CSNB224 – AAG 2007 Process Trace.. The processor stops executing process B and moves on to process C. After time-out, the processor moves back to process A. When the process times out, process B is still waiting for I/O operation to complete, so the dispatcher moves on to process C again.
13
CSNB224 – AAG 2007 Dispatcher Is an OS program that moves the processor from one process to another It prevents a single process from monopolizing processor time It decides who goes next according to a scheduling algorithm (will be discussed on chap 9) The CPU will always execute instructions from the dispatcher while switching from process A to process B
14
CSNB224 – AAG 2007 Process Creation Reasons for process creation: Submission of a batch job User logs on Created to provide a service such as printing (ex: printing a file) Process creates another process (Process Spawning)
15
CSNB224 – AAG 2007 Process Termination General reasons for process termination: Batch job issues Halt instruction User logs off Process executes a service request to terminate (Quit an application) Error and fault conditions
16
CSNB224 – AAG 2007 Process Termination.. Specific reasons for process termination: Normal completion Time limit exceeded Memory unavailable Bounds violation Protection error example write to read-only file Arithmetic error
17
CSNB224 – AAG 2007 Process Termination.. Time overrun I/O failure Invalid instruction Privileged instruction Data misuse Operating system intervention Parent terminates so child processes terminate Parent request
18
CSNB224 – AAG 2007 Two-State Process Model Process may be in one of two states Running Not-running
19
CSNB224 – AAG 2007 Two-State Process Model.. When the OS creates a new process, it enters that process into Not Running State. The existence of the process is known by the OS and is waiting for an opportunity to execute. Running process will be interrupted from time to time and dispatcher will select a new process to run. Process will moves from the Running state to Not Running state, another process will moves to the Running state.
20
CSNB224 – AAG 2007 Two-State Process Model.. Each process must be represented in some way so that OS can keep track of it. There must be some information relating to each process, including current state and location of main memory. Process that are not running must be kept in some sort of queue, waiting their turn to be execute. Figure 3.4b suggests a structure to deploy two- state process model.
21
CSNB224 – AAG 2007 Not-Running Process in a Queue
22
CSNB224 – AAG 2007 Two-State Process Model.. There is a single queue in which each entry is a pointer to a particular process. The queue must consist of linked list of data blocks, in which each block represents one process. The queue if first in first out (FIFO) list and the processor operates in Round robin.
23
CSNB224 – AAG 2007 Process Queuing suggested in Figure 3.4b will be effective if all processes were always ready to execute But, this implementation is inadequate because some process that are in Not Running state either ready to execute blocked because of waiting for I/O operation complete.
24
CSNB224 – AAG 2007 Process.. By using queuing on fig. 3.4b, the dispatcher has to scan the queue looking for the process that is not blocked and has been in queue the longest. A way to tackle this situation is to split the Not Running state into two, which are: Ready state: Ready to execute Blocked state: waiting for I/O Now, instead of two states we have three states Ready, Running, Blocked
25
CSNB224 – AAG 2007 Process.. For a good measure, added two additional states that will be useful for process management (New and Exit state). New state: OS performed the necessary actions to create the process –Process ID –Tables needed to manage the process but has not yet committed to execute the process (not yet admitted) – because resources are limited
26
CSNB224 – AAG 2007 Process.. Exit state: Termination moves the process to this state. It is no longer eligible for execution Tables and other info are temporarily preserved for auxiliary program –Ex: accounting program that cumulates resource usage for billing the users The process (and its tables) gets deleted when the data is no more needed
28
CSNB224 – AAG 2007 A Five-State Model Running the process that is currently being executed. Ready a process that is prepared to execute when given the opportunity. Blocked a process that cannot execute until some event occurs, such as the completion of I/O operation. New a process that has just been created but not being admitted to the pool of executable process by the OS (not being loaded in the main memory). Exit a process that has been released from the pool of executable processes by the OS, either because it halted or aborted for some reason.
29
CSNB224 – AAG 2007 Process Transitions Figure 3.5 indicates the possible state transition as follows: Null New A new process is created to execute a program. New Ready OS will move the process from New to Ready state when it is prepared to take an additional process. Ready Running When it is time, the dispatcher selects a new process to run
30
CSNB224 – AAG 2007 Process Transitions.. Running Exit The currently Running process is terminated by the OS if he process indicates that it has completed or if it aborts. Running Ready the running process has expired his time slot the running process gets interrupted because a higher priority process is in the ready state
31
CSNB224 – AAG 2007 Process Transitions.. Running Blocked When a process requests something for which it must wait –a service that the OS is not ready to perform –an access to a resource not yet available –initiates I/O and must wait for the result –waiting for a process to provide input (IPC) Blocked Ready When the event for which it was waiting occurs
32
CSNB224 – AAG 2007 Process Transitions.. Ready Exit Not shown on the state diagram. Parent may terminate the child process. Parent terminates, all child processes associated also terminated. Blocked Exit The comments under the preceding item apply.
33
CSNB224 – AAG 2007 Process Transitions.. Figure 3.6 shows the movement of each process among the states from Figure 3.3.
34
CSNB224 – AAG 2007 Process Transitions.. Figure 3.7a suggests the way in which a queuing discipline might be implemented. There are two queue: Ready queue and Blocked queue. When the event occurs, OS must scan the entire block queue, searching for those processes waiting on that event. But in large OS, there are hundreds or thousands of processes in that queue. It is efficient to have a number of queues, one for each event. (Fig 3.7b)
35
CSNB224 – AAG 2007 Using Two Queues
37
CSNB224 – AAG 2007 Suspended Processes So far, all the processes had to be in main memory. Even with virtual memory, keeping too many processes in main memory will deteriorate the system’s performance. Processor is faster than I/O so all processes could be waiting for I/O. Thus even with multiprogramming, processor could be idle most of the time.
38
CSNB224 – AAG 2007 Suspended Processes.. Solutions for this problem are: 1.Main memory could be expanded to accommodate more processes. Disadvantage: –Cost –Result for larger processes not more processes.
39
CSNB224 – AAG 2007 Suspended Processes.. 2.Swapping Swap these processes to disk to free up more memory. Blocked state becomes suspend state when swapped to disk. The OS may need to suspend some processes, ie: to swap them out to disk. There are 2 new states: –BLOCKED SUSPEND: blocked processes which have been swapped out to disk –READY SUSPEND: ready processes which have been swapped out to disk
40
CSNB224 – AAG 2007 One Suspend State
41
CSNB224 – AAG 2007 Two Suspend States Process transition: Check text book page 122 and 123
42
CSNB224 – AAG 2007 Characteristics of Suspended Process 1. The process is not immediately available for execution. 2. The process may or may not be waiting for an event 3. The process was placed in a suspended state by an agent; either itself, the OS, or the parent process. For the purpose of preventing its execution. 4. The process may not be removed from this state until the agent explicitly orders the removal.
43
CSNB224 – AAG 2007 Reasons for Process Suspension
44
CSNB224 – AAG 2007 Process Description OS control events within the computer system. Schedules and dispatches processes for execution by the processor, allocates resources to processes, and responds to requests by user programs for basic services. OS as an entity that manages the use of system resources by processes. (figure 3.9)
45
CSNB224 – AAG 2007 Process Description.. Figure 3.9 shows multiprogramming environment. There are a number of processes (P 1,…P n ) that have been created and exists in virtual memory. Each process during the course of its execution, need access to certain system resources, including the processor, I/O devices and main memory.
47
CSNB224 – AAG 2007 Process Description.. In the figure, process P 1 is running: at least part of it in the main memory and it has control of two I/O devices. Process P 2 also in main memory but is blocked waiting for an I/O device allocated for P 1. Process P n has been swapped out and is therefore suspended.
48
CSNB224 – AAG 2007 Operating System Control Structures For the OS to manage the processes and resources, it must have information about the current status of each process and resource Tables are constructed for each entity the operating system manages Figure 3.10 shows four different types of tables maintained by the OS: Memory tables I/O tables File tables Process tables
50
CSNB224 – AAG 2007 Memory Tables Used to keep track both main and secondary memory. Include the following information: 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
51
CSNB224 – AAG 2007 I/O Tables To manage the I/O devices and channels of the computer system. At any time, I/O device is 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 location in main memory being used as the source or destination of the I/O transfer
52
CSNB224 – AAG 2007 File Tables The tables provide information about: Existence of files Location on secondary memory Current Status Other attributes Sometimes this information is maintained by a file-management system
53
CSNB224 – AAG 2007 Process Table To manage process, the OS must know: Where process is located Attributes necessary for its management Process ID Process state Location in memory
54
CSNB224 – AAG 2007 Process Control Structures.. Process includes set of programs to be executed Data locations for local and global variables Any defined constants Stack Process control block Collection of attributes Process image Collection of program, data, stack, and attributes
55
CSNB224 – AAG 2007 Process Location Location of process image will depend on the memory management scheme being used. Simplest case, the process image is maintained as a contiguous block of main memory. This block is maintained in secondary memory A small portion of process image must be maintained in main memory, so the OS can manage the process.
56
CSNB224 – AAG 2007 Process Location.. To execute the process, the entire process image or a portion of process must be loaded into main memory. Thus the OS needs to know the location of each process on disk and in main memory.
57
CSNB224 – AAG 2007 Process Attributes The Process Control Block information can be grouped into three general categories: 1.Process identification 2.Processor state information 3.Process control information
58
CSNB224 – AAG 2007 Process Identification A few numeric identifiers may be used Unique process identifier Indexes (directly or indirectly) into the primary process table User identifier The user who is responsible for the job Identifier of the process that created the process
59
CSNB224 – AAG 2007 Processor State Information Contents of processor register. User-visible registers Control and status register Stack pointers Program status word (PSW) Contains status information Example: the EFLAGS register on Pentium machines
60
CSNB224 – AAG 2007 Process Control Information Scheduling and state information Process state (ie: running, ready, blocked...) Priority of the process Event for which the process is waiting (if blocked) Data structuring information may hold pointers to other PCBs for process queues, parent-child relationships and other structures
61
CSNB224 – AAG 2007 Process Control Information Inter-process communication may hold flags and signals for IPC Process privileges Ex: access to certain memory locations... Memory management pointers to segment/page tables assigned to this process Resource ownership and utilization resource in use: open files, I/O devices... history of usage (of CPU time, I/O...)
62
CSNB224 – AAG 2007 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
63
CSNB224 – AAG 2007 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. Typically, there are from 8 to 32 of these registers, although some RISC implementations have over 100.
64
CSNB224 – AAG 2007 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
65
CSNB224 – AAG 2007 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.
66
CSNB224 – AAG 2007 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
67
CSNB224 – AAG 2007 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.
68
CSNB224 – AAG 2007 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.
69
CSNB224 – AAG 2007 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.
71
CSNB224 – AAG 2007 Modes of Execution To provide protection to PCB (and other OS data) most processors support at least 2 execution modes: 1.User mode Less-privileged mode User programs typically execute in this mode 2.System mode, control mode, or kernel mode More-privileged mode Kernel of the operating system
72
CSNB224 – AAG 2007 Modes of Execution Reasons using two modes because it is necessary to protect the OS and other OS tables such as PCB form interference by user program. In the kernel mode, the software has complete control of the processor and all its instruction, registers and memory. This level of control is not necessary and for safety is not desirable for user programs.
73
CSNB224 – AAG 2007 Process Creation Steps involved in creating the process: 1. Assign a unique process identifier 2. Allocate space for the process 3. Initialize the process control block 4. Set the appropriate linkages 5. Create or expand other data structures Ex: maintain an accounting file
74
CSNB224 – AAG 2007 Process Switching Process switch from one state to another. Eg: A running process is interrupted and the OS assigns other process to the Running state and turns control over the process. Several design issues raised: 1.What events trigger a process switch? 2.Must recognize the distinction between mode switching and process switching? 3.What must the OS do to the various data structures under its control to achieve process switch?
75
CSNB224 – AAG 2007 When to Switch a Process A process switch may occur whenever the OS has gained control of CPU. i.e. when: Supervisor Call explicit request by the program (ex: file open). The process will probably be blocked Trap An error resulted from the last instruction. It may cause the process to be moved to the Exit state Interrupt the cause is external to the execution of the current instruction. Control is transferred to Interrupt Handler
76
CSNB224 – AAG 2007 When to Switch a Process Example of interrupt: Clock interrupt process has executed for the maximum allowable time slice and is transferred to Ready state. I/O interrupt first move the processes that where waiting for this event to the ready (or ready suspend) state then resume the running process or choose a process of higher priority
77
CSNB224 – AAG 2007 When to Switch a Process Memory fault memory address is in virtual memory so it must be brought into main memory Thus move this process to Blocked state (waiting for I/O to complete)
78
CSNB224 – AAG 2007 Mode Switching It may happen that an interrupt does not produce a process switch The control can just return to the interrupted program Then only the processor state information needs to be saved on stack (ref. Chap 1) This is called mode switching (user to kernel mode when going into Interrupt Handler) Less overhead: no need to update the PCB like for process switching
79
CSNB224 – AAG 2007 Change of Process State Steps involved in process switching: 1. Save context of processor including program counter and other registers 2. Update the process control block of the process that is currently running 3. Move process control block to appropriate queue - ready, blocked 4. Select another process for execution 5. Update PCB of the selected process
80
CSNB224 – AAG 2007 Change of Process State 6. Update memory-management structures. 7. Restore CPU context from that of the selected process.
81
CSNB224 – AAG 2007 Execution of the OS Up to now, the process we were referring to is “user process” If the OS is just like any other collection of programs, is the OS a process? If so, how it is controlled? The answer depends on the OS design. Figure 3.14 illustrates a range of approaches that are found in various contemporary OS.
83
CSNB224 – AAG 2007 Non-process Kernel The concept of process applies only to user programs OS code is executed as a separate entity in privilege mode OS code never gets executed within a process
84
CSNB224 – AAG 2007 Execution within User Process Virtually all OS code gets executed within the context of a user process On Interrupts, Traps, System calls: the CPU switch to kernel mode to execute OS routine within the context of user process (mode switch) Control passes to process switching functions (outside processes) only when needed
85
CSNB224 – AAG 2007 Execution within User Process Check figure 3.15. OS code and data are in the shared address space and are shared by all user processes Separate kernel stack for calls/returns when the process is in kernel mode Within a user process, both user and OS programs may execute (more than 1)
87
CSNB224 – AAG 2007 Execution of the Operating System Process-Based Operating System major kernel functions are separate processes Useful in multi-processor or multi-computer environment
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.