Process Scheduling | Principles of Operating Systems
Remember that process is a program in execution. Program becomes process when it is loaded into main memory (RAM). The objective of multiprogramming is to have some process running at all times, so as to maximize CPU utilization.
As processes enter the system, they are put into a job queue. This QUEUE consists of all processes in the system. The processes that are residing in main memory and are ready and waiting to execute are kept on a list called Ready Queue. The Queue is generally stored as a linked list. A ready queue header contains pointers to the first and final PCBs (Process Control Blocks) in the list. This information is known as context switch. The context of a process is represented in the PCB of a process. It includes the value of the CPU registers, the process state and memory management information.
When the context switch occurs, the kernel saves the context of the old process in its PCB and loads saved context of the new process scheduled to be run. Context switch time is pure overhead, because the system does no useful work while switching. Its speed varies from machine to machine, depending on the memory speed, number of registers that must be copied and the existence of special instructions (such as single instruction to load or store all registers). Typical speeds range from 1 to 1000 microseconds.
All the jobs that enter the system are kept in the job pool (QUEUE). This pool consists of all processes residing on disk waiting for allocation of main memory. If several jobs (= processes) are ready to be brought into main memory, and if there is not enough room for all of them, then the system must choose among them. This is called job (process) scheduling.
In any multiprogramming system, the CPU switches from process to process quickly; running each for 10s or 100s of msec. Strictly speaking, at any instant of time, the CPU is running only one process. Switching of CPU from one program to other is known as multiprogramming. Real life example of multiprogramming is: a lawyer does not work for only one client at a time. While one case is waiting to get trial or have papers typed, the lawyer can work on another case. When multiprogramming is used, the CPU utilization can be improved.