OS 2.2: Process Scheduling
Scheduling Criteria
1. CPU utilization (max) 2. Throughput (max) 3. Turnaround time (min) 4. Waiting time (min) 5. Response time (min) Can't Trip Today With Renae CPU utilization - keep the CPU as busy as possible Throughput - amount of processes that complete their execution per time unit Turnaround time - amount of time to execute a particular process Waiting time - amount of time a process has been waiting in the ready queue Response time - amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)
Process Scheduling
>>> Main Priority: Maximize CPU. Process scheduler selects among available processes for next execution on CPU AND maintains scheduling queues of processes. Scheduling: quickly switch processes onto CPU for time sharing. List of Queues: Job queue - set of all processes in the system Ready queue - set of all processes residing in main memory, ready and waiting to execute Device queues - set of processes waiting for an I/O device **Processes can migrate among the various queues.
Multilevel Queue Scheduling
Classify processes and put them in different scheduling queues. Different scheduling priorities depending on process group priority. In a multi-level queue scheduling algorithm, there will be 'n' number of queues, where 'n' is the number of groups the processes are classified into. Each queue will be assigned a priority and will have its own scheduling algorithm. For the process in a queue to execute, all the queues of priority higher than it should be empty, Unlike multilevel queue scheduling algorithm where processes are permanently assigned to a queue, >>>KNOW>>>Multilevel Feedback queue scheduling allows a process to move between queues.
Schedulers, Short-term vs Long-term
Long-term scheduler (or job scheduler) Vs Short term scheduler (or CPU scheduler) Long-term scheduler (or job scheduler) - selects which processes should be brought into the ready queue Short-term scheduler (or CPU scheduler) - selects which process should be executed next and allocates CPU Short-term scheduler is invoked very frequently (milliseconds, must be fast). Long-term scheduler is invoked very infrequently (seconds, minutes, may be slow) **Schedulers operate by using algorithms to help in the scheduling process. *Medium-term scheduler can be added if degree of multiple programming needs to decrease
Non-preemptive Vs Preemptive
In non-preemptive algorithms a process enters the running state and cannot be preempted until it completes its allotted time. In preemptive the scheduler is using priority as a drive, and preempt a low priority running process when a high priority process enters its ready state.
I/O-bound process vs CPU-bound process
Processes can be described as either: I/O-bound process - spends more time doing I/O than computations, many short CPU bursts CPU-bound process - spends more time doing computations, a few very long CPU bursts ***NOTE: An I/O burst is when the CPU is waiting for I/O for further execution. After I/O burst, the process goes into the ready queue for the next CPU burst (when the process is being executed in the CPU). CPU-I/O Burst Cycle: Process execution consists of a cycle of CPU execution and I/O wait. When the CPU is done, then there is more I/O >>>So, a CPU burst is followed by I/O burst
Dispatcher
The Dispatcher module gives control of the CPU to the process selected by the short-term scheduler. May switch context, switch to user mode and/or jump to the proper location in the user program to restart that program Dispatch latency: The term dispatch latency describes the amount of time it takes for the dispatcher to stop one process and start another running. With a scheduler written specifically to honor application priorities, realtime applications can be developed with a bounded dispatch latency. Remember: Context switching: dispatcher saves the state of the process that was previously running and loads the initial or previously saved state of the new process.
First-Come, First-Served (FCFS), Shortest-Job-First (SJF), Shortest-remaining-time-first (SRTF) and Round Robin (RR) Scheduling
FCFS: Exactly as sentence suggests. SJF: the process with the smaller burst time will have to be executed first. SRTF: preemptive SJF RR: FCFS but with quantum (time limit) Quantum is also know as time slice. If quantum value is extremely big then it is basically FCFS. If the burst time is smaller than quantum then process uses what is needed and moves to the next one. Remember: Burst time is the (processing allocating) time needed for the execution to be completed. Use a Gantt Chart for Scheduling FCFS easy implementation but average waiting time can be high. SJF minimize waiting time but the processor must know from the start how much process time will take which is hard for interactive systems. SRTF hard for interactive systems too. Priority treated FCFS => most common Problem = Starvation: low priority processes may never execute Solution = Aging: as time progresses increase the priority of the process.
Quantum/ Time Slice
MEMORIZE: Time slice refers to a period of time in which a process is permitted to run in a preemptive multitasking system, AKA, Quantum Preemptive: (stop or pause a current scheduled task in favor of a higher priority) We can have time slicing in digital broadcasting with simultaneous performance of two or more data streams. The scheduler runs once every time slice to choose the next process to run. Sometimes a parent process can die and leave the child orphaned. This child process will be adopted by the init process. Now in Unix specifically a child process uses a fork system call where is mainly a clone of the parent process and then both parent and child continue to run as expected. So forking is mainly when a process creates a copy of itself and is treated as a system call. Fork is generally used for creation of new processes. Creates the child process of the caller. On return from the fork() system call, the two processes have identical copies of their user-level context.
Swapping and Context Switch
Remove process from memory, store on disk, bring back in from disk to continue execution. When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process via a context switch This allows multiple processes to share a single CPU, and is an essential feature of a multitasking operating system. Context-switch time is overhead; the system does no useful work while switching The more complex the OS and the PCB (Printed Circuit Boards), the longer the context switch. Also, time dependent on hardware support. Some hardware provides multiple sets of registers per CPU, so multiple contexts can be loaded at once
CPU Scheduler
Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them CPU scheduling decisions take place when a process switches states.
