Process Switching

by : Jesse Miller

At some time, a running process is interrupted and the operating system assigns another process to the running state and turns control over that process.

A process switch may occur any time that the operating system has gained control from the currently running process. Considering that the system interrupts, there are two types of system interrupts out of which one is simply referred to as an interrupt and the other as a trap.

The former is caused by some sort of event that is external to and independent of the currently running process, such as the completion of an I/O operation. The latter relates to an error or exception condition generated within the currently running process, such as an illegal attempt to access a file.

With an ordinary interrupt, control is first transferred to an interrupt handler, which does some basic house keeping and then branches to an operating system routine that is concerned with the particular type of interrupt that has occurred.

The operating system determines whether the currently running process has been executing for the maximum allowed time slice. If so, this process must be switched to a ready state and another process dispatched. This is known as clock interrupt. The operating system determines exactly what I/O action has occurred. If the I/O action constitutes an event for which one or more processes are waiting, then the operating system moves all the corresponding blocked processes to the Ready state( and blocked, suspended process to the Ready, suspended state).

The operating system must then decide whether to resume execution of the process currently in the Running state to preempt that process for a higher-priority Ready process.

The processor encounters a virtual memory address reference for a word that is not in main memory. The operating system must bring in the block of memory containing the reference from secondary memory to main memory. After the I/O request is issued to bring the block of memory, the operating system may perform a context switch to resume execution of another process; the process with the memory fault is placed in a blocked state. After the desired block is brought into memory, then that particular process is placed in a Ready state.