Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Process Description z Process y Process description y Key concept of the process y Examples of the process z z z z z Two-state Process Model Uniprogramming Mutliprogramming Process Creation Process Termination Major Requirements of an Operating System z Interleave the execution of the number of processes to maximize processor utilization while providing reasonable response time z Allocate resources to processes z Support interprocess communication and user creation of processes Process z Execution of an individual program (a sequence of instructions) in the context of a particular process state z Can be traced y list the sequence of instructions that execute z Also called a task Key Concept of Process z processes are separated: no process can directly affect the state of another process. Process is a Key OS Abstraction that Users See z The environment you interact with when you use a computer is built up out of processes. Process Examples z The shell you type stuff into is a process. z When you execute a program you have just compiled, the OS generates a process to run the program. z Your WWW browser is a process. Dispatcher z Program that moves the processor from one process to another z Prevents a single process from monopolizing processor time Two-State Process Model Dispatch Enter Not Running Running Exit Pause (a) State transition diagram Queue Enter Dispatch Exit Processor Pause (a) Queuing diagram Uniprogramming z Uniprogramming: only one process at a time z Typical uniprogramming example: DOS. Problem: users often wish to perform more than one activity at a time and uniprogramming does not allow this. z Uniprogrammed systems put in things like memory-resident programs that invoked asynchronously. One key problem with DOS is that there is no memory protection - one program may write the memory of another program, causing bugs. Multiprogramming z Multiprogramming: multiple processes at a time z Typical multiprogramming example: Unix Problem : which processes get to use the physical resources of the machine and when? z Standard solution: To use preemptive multitasking - OS runs one process for a while, then takes the CPU away from that process and lets another process run. Must save and restore process state. Key issue: Fairness for Multiprogramming z Must ensure that: all processes get their fair share of the CPU. Process Creation z Submission of a batch job z User logs on z Create to provide a service such as printing z Spawned by an existing process Process Termination z Batch job issues Halt instruction z User logs off z Process executes a service request to terminate z Error and fault conditions Reasons for Process Termination z z z z z Normal completion Time limit exceeded Memory unavailable Bounds violation Protection error y example write to read-only file z Arithmetic error z Time overrun y process waited longer than a specified maximum for an event Reasons for Process Termination z I/O failure z Invalid instruction y happens when try to execute data z Data misuse z Operating system intervention y such as when deadlock occurs z Parent terminates so child processes terminate z Parent request Processes z Not-running y ready to execute z Blocked y waiting for I/O z Dispatcher cannot just select the process that has been in the queue the longest because it may be blocked A Five-State Model (1) z z z z z Running Ready Blocked New Exit Five-State Process Model (2) Dispatch New Admit Ready Release Running Time-out Event Occurs Blocked Event Wait Exit A Five-State Model Running (3) z Running: the process that is currently being executed. z We will assume a computer with a single processor, so at most one process can be in this state at a time A Five-State Model Running (4) z Running > Exit: the currently running process is terminated by the operating system if the process indicated that it has completed, or if it aborts. z Running > Ready: the running process has reached the maximum allowable time for uninterrupted execution. z Running > Blocked: a process requests something for which it must wait - I/O operation. A Five-State Model - Ready (5) z Ready A process that is prepared to execute when given the opportunity. z Ready > Running When it is time to select a new process to run, the Operating system choose one of the processes in the ready state. The issue is which process to choose. A Five-State Model Blocked (6) z Blocked A process that can not execute until some event occurs, such as the completion of an I/O operation. z Blocked > Ready A process in the Blocked state is moved to the Ready state when the event for which it has been waiting occurs A Five-State Model - New (7) z New: a process that has just been created but has not yet been admitted to the pool of executable processed by the operating system. z Null > New: a new process is created to execute a program. This event occurs for new job, logon, and create child process. z New > Ready: When the process is prepared to take on an additional process. A Five-State Model - Exit (8) z Exit: A process that has been released from the pool of executable processes by the operating system, either because it halted or because it aborted for some reason. Single Blocked Queue Ready Queue Release Dispatch Admit Processor Time-out Event Wait Event Occurs Blocked Queue Multiple Blocked Queues Ready Queue Release Dispatch Admit Processor Time-out Event 1 Wait Event 1 Occurs Event 1 Queue Event 2 Wait Event 2 Occurs Event 2 Queue Suspended Processes - Do Better than Five-State Process Model z Processor is faster than I/O so all processes could be waiting for I/O z Swap these processes to disk to free up more memory z Blocked state becomes suspend state when swapped to disk z Two new states y Blocked, suspend y Ready, suspend Process State Transition Diagram with Two Suspend States - SevenState Process Model (1) Ready Admit Admit Suspend Dispatch Activate Ready, suspend Ready Suspend Running Time out Event Occurs Event Occurs Activate Blocked, suspend Blocked Suspend Event Wait Exit A Seven-State Model Assumption (2) z The discussion so far has assumed that virtual memory is not in use and that a process is either all in main memory or all out of memory. z With a virtual memory scheme, it is possible to execute a process that is only partially in main memory. A Seven-State Model States (3) z Ready: The process is in main memory and available for execution. z Blocked: The process is in main memory and awaiting an event. z Blocked, suspend: The process in in secondary memory and awaiting an event. z Ready, suspend: The process is in secondary memory but is available for execution as soon as it is loaded into main memory. A Seven-State Model (4) z Blocked > Blocked, suspend If there are no ready processes, then at least one blocked process is swapped out to make room for another process that is not blocked. A Seven-State Model (5) z Blocked, suspend > Ready, suspend A process in the Blocked, suspend state is moved to the Ready, suspend state when the event for which it has been waiting occurs. A Seven-State Model (6) z Ready, suspend > Ready When there are no ready processes in main memory, the operating system will need to bring one in to continue execution. z It might be the case that a process in the ready, suspend state has higher priority than any of the processes in the Ready state. In that case, the operating system designer may dedicate that it is more A Seven-State Model (7) z Ready > Ready,suspend It may be necessary to suspend a ready process if that is the only way to free a sufficiently large block of main memory. z The operating system may choose to suspend a lower-priority ready process rather a higher-priority blocked process if it believes that the blocked process will be ready soon. A Seven-State Model (8) z New > Ready, suspend and New > Ready When a new process is created, it can either be added to the Ready queue or the Ready, suspend queue. z There would always be insufficient room in main memory for a new process; hence the use of the New > Ready, suspend transition. A Seven-State Model (9) z Blocked, suspend > Blocked A process terminates, freeing some main memory. There is a process in the Block,suspend queue with a higher priority than any of the processes in the Ready, suspend queue and the operating system has reason to believe that the blocking event for that process will occur soon. A Seven-State Model (10) z Running > Ready, suspend If, however, the operating system is preempting the process because a higherpriority process on the Blocked, suspend queue has just become unblocked, the operating system could move the running process directly to the Ready, suspend queue and free some main memory. A Seven-State Model (11) z Various > Exit *Typically, a process terminates while it is running, either because it has completed or because of some fatal fault condition *However, in some operating systems, a process may be terminated by the process that created it or when the parent process is itself terminated (think about fork system call). If this is allowed, then a process in any state can be moved to the Reasons for process Suspension (1) z Swapping The operating system needs to release sufficient main memory to bring in a process that is ready to execute. z Other OS reason The operating system may suspend a background or utility process or a process that is suspected of causing a problem. z Interactive user request A user may wish to suspend execution of a program for purpose of debugging or in connection with the use of a resource. Reasons for process Suspension (2) z Timing A process may be executed periodically (e.g., an accounting or system monitoring process) and may be suspended while waiting for the next time interval. Parent process request A parent process may wish to suspend execution of a descendent to examine or modify the suspended process, or to coordinate the activity of various descendents.