The second week of CST 334 gave us an overview of processes and how they are scheduled by the OS.
Processes are the mechanism that OSes use to execute programs. The OS is responsible for transforming a program, stored as a file on disk, into a process that resides in memory. To accomplish this the OS allocates an address space – which contains the program’s code, data, heap, and stack. After initialization the OS puts the process into the ready state, which notifies the scheduler that the process is available for execution. Processes exist in two other main states: the running state, and the blocked state. The running state signifies that the process is currently executing on the CPU. The blocked state indicates that the process is waiting for (blocked) by some operation, most commonly IO. A blocked process gives up its time slice, and OSes use this opportunity to run other processes and keep the CPU active.
An OS’s scheduler is responsible for determining which process should execute on the CPU at any given time. This is a complicated task, with many different methods available. One such method is the Multi-level Feedback Queue. MLFQ uses queues of different priority levels, assigning processes to these queues over time to determine which process should execute during a time slice. Processes of higher priority always execute first; processes of equal priority execute in Round Robin fashion. Essentially, processes are assumed to have short runtimes initially, and are placed in a high priority queue on creation. When these processes fail to complete, or fail to yield during a time slice, they are demoted. All processes are periodically promoted to the highest priority level to prevent starvation of low-priority processes. This system attempts to optimize for turnaround time by running short jobs first, and attempts to keep response time high by running same-priority processes in Round Robin fashion.
The OS uses a mechanism called a “context switch” to change the currently executing program. A voluntary context switch occurs when a process initiates a system call that blocks the process. During this system call the OS may decide to change the currently running process. An involuntary context switch occurs during a timer interrupt, in which the hardware executes a timer handler in the kernel, handing control of the CPU back to the OS. The OS scheduler then decides which program should execute during the next time slice, and executes a context switch to hand control over.
No comments:
Post a Comment