Está en la página 1de 4

Distributed Computing Communication Architecture ISO layers Protocols 1. 2. 3. 4.

Process Migration Synchronisation Mutual Exclusion Distributed Deadlock

Monday, March 01, 2004 1. 2. 3. 4. Process switch vs. Context Switching (partly covered) Operating Systems and user Processes Micro Kernels Processes and Threads

What is the difference between a context switch and a process switch? Therefore what is a process switch and what is a context switch? Process Switching When/How? A process switch occurs whenever the operating system has gained control from the currently running process. 1. Interrupts (These are external to the running program) a. Clock Interrupt The OS determines whether the currently running process has been executing for the maximum allowable time slice. If so the process is switched to a ready state and another process dispatched. b. IO interrupt - The OS determines what IO action has occurred. If it is an event for which one or more processes are waiting then the OS moves all the corresponding blocked processes to the ready state and blocked suspended processes to the ready suspended state. The OS then decides whether to continue execution of the process currently in the running state or to preempt that process for a higher priority ready process c. Memory Fault The processor encounters a virtual memory address reference for data that is not in main memory. The OS must bring in the block (i.e. page or segment) of memory containing the reference from secondary memory to main memory. The process is placed in a blocked state. After the desired block is brought into main memory the process is shifted to ready state. 2. Trap With a trap the OS determines whether the error is fatal. If so the currently running process is moved to the exit state. If the error is not fatal the OS may attempt some recovery procedure, or it may simply notify the user. It may or may not do a process switch. 3. Supervisor Call When the OS is activated by a Supervisor call from the program that is being executed e.g. for a file open instructions. This results to a transfer to a routine that is part of the OS code. Generally the use of a system/supervisor call results in placing the user process in the blocked state. Context Switching In most OS the occurrence of an interrupt does not necessarily result in a process switch. After the interrupt handler has executed the currently running process may resume execution. So only the processor state information needs to be saved when the interrupt occurs. The saving and restoring functions are performed in hardware. A process switch is more expensive in terms of performance overhead.

Steps in a full process switch


1. Save processor context including processor counter and other registers. 2. Update Process Control Block (PCB) of currently running process, indicating state change, reasons for the change and also accounting information. 3. Move the Process Control Block of the process to appropriate queue. (Ready, Blocked, etc) 4. Select another process for execution. 5. Update Process Control Block of selected process. 6. Update the memory management data structures. This depends on how address translation is managed. 7. Restore the context of the processor to that which existed at the time the selected process was last switched out of the Running State by loading in the Program Counter and registers value in the stack. Operating Systems and User Processes - Acts as a buffer between user applications and the hardware of the Personal Computer. It also acts as an efficient resource manager. A. Separate Kernel It is a traditional and common approach. When the currently running process is interrupted or when it issues a supervisor call. The processor context is saved and the control is passed to the kernel. The OS has its own region of memory and its own system stack for controlling procedure and returns. The OS can perform any desired The OS can perform any desired function and restore the context of the interrupted process. Alternately the OS can dispatch another process; this depends on the reason for the interruption and the circumstances. B. Execution within user process In smaller machines it is common to execute virtually all OS software in the context of a user process. The view is that the OS is just a collection of routines that the user calls to perform different functions and executed within the environment of the user process. The corresponding process image shows a separate kernel stack used to manage calls and returns while the process is in kernel mode, the OS code and data are in the shared address space and are shared by all user processes. When an interrupt, trap or supervisor call occurs the processor is placed in kernel mode and control is passed to the OS for this, the processor context is saved and a context switch occurs to an OS routine but execution continues within the current user process. This is one of the key advantages of this approach. A user program has been interrupted to run some OS routine and then resume and all this has occurred without incurring the penalty of two process switches. C. Process Based Operating System The merit of this system is that it imposes a program design discipline that encourages the use of a modular Operating System with minimal, clean interfaces. Some non critical OS functions can be conveniently implemented as separate processes. For example a monitor program that records the utilization of various resources and the rate of progress

of the user processes. Implementing the OS as a set of processes is useful in a multiprocessor or multi-computer environment. In which some of the OS services can be shipped out to dedicated processors to improve performance.

También podría gustarte