PROCESS STATE
Processes can be any of the following states :
- New - The process is being created.
- Ready - The process is waiting to be assigned to a processor.
- Running - Instructions are being executed.
- Waiting - The process is waiting for some event to occur(such as an I/O completion or reception of a signal).
- Terminated - The process has finished execution.
Context Switching
The process of saving the context of one process and loading the context of other process is known as Context Switching. In simple term, it is like loading and unloading of the process from running state to ready state.
The process of saving the context of one process and loading the context of other process is known as Context Switching. In simple term, it is like loading and unloading of the process from running state to ready state.
When does Context switching happen?
1. When a high priority process comes to ready state, compared to priority of running process
2. Interrupt Occurs
3. User and Kernel mode switch: (It is not necessary though)
4. Preemptive CPU scheduling used.
1. When a high priority process comes to ready state, compared to priority of running process
2. Interrupt Occurs
3. User and Kernel mode switch: (It is not necessary though)
4. Preemptive CPU scheduling used.
The steps in a full process switch are:
- Save the context of the processor, including program counter and other registers.
- Update the process control block of the process that is currently in the Running state. This includes changing the state of the process to one of the other states (Ready; Blocked; Ready/Suspend; or Exit). Other relevant fields must also be updated, including the reason for leaving the Running state and accounting information.
- Move the process control block of this process to the appropriate queue(Ready; Blocked on Event i ; Ready/Suspend).
- Select another process for execution.
- Update the process control block of the process selected. This includes changing the state of this process to Running.
- Update memory management data structures. This may be required, depending on how address translation is managed.
- 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 previous values of the program counter and other registers.
Mode switching
A user process undergoes a mode switch when it needs access to system resources. This is implemented through the system call interface or by interrupts such as page faults.
There are two modes:
- User mode
- Kernel mode
Processor time spent in user mode (application and shared libraries) is reflected as user time in the output of commands such as the vmstat, iostat, and sar commands. Processor time spent in kernel mode is reflected as system time in the output of these commands.
No comments:
Post a Comment