Answer to Question 2 -- 10 points

When an operating system is ready to relinquish control of the CPU, it usually must choose to execute one of a collection of ready processes. The scheduling algorithm determines which of the processes should be executed.

Round-robin (RR) scheduling is basically FIFO scheduling where the running job is preempted at regular intervals. All processes that are ready to execute are held in a queue, and the operating system gives the CPU to the process at the head of the queue. Processes go onto the end of the ready queue when they go from a non-ready to a ready-state, and when they are preempted. This preemption is enabled by a hardware timer that interrupts the CPU at a known interval. The operating system defines a time quantum, which is a multiple of the timer interval. If a process uses the CPU for an entire time quantum, then at the next timer interrupt, it is put at the end of the ready queue and the next job on the queue is given the CPU.

Round-robin scheduling is much better than, for example, FIFO in terms of turnaround and maximum waiting time. Although it does not attempt to approach shortest-job-first scheduling, it does guarantee that if there are n ready processes at any one time, then each will get at least 1/n-th of the CPU every n time quanta. If most of these jobs are I/O bound, then the CPU-bound jobs will get more of the CPU, but in a egalitarian fashion.

One of the weaknesses of RR scheduling is that preempting a process involves a context-switch, which is expensive on most machines, and is pure overhead. Thus, if you are preempting lots of processes, your system is not getting good CPU utilization. The rule of thumb that the book gives is that if at least 80% of the processes relinquish the CPU voluntarily before their time quantum expires, then the CPU utilization will be good.

To improve upon this weekness, you can do one of a few things. First, to attempt to approximate SJF scheduling, you can add priorities to your processes, and schedule the high-priority ones first. The timer interrupt makes sure that yor reevaluate process priorities at regular intervals. This is basically how Unix scheduling works.

You may also try to improve the scheduling by tuning the time quantum to the nature of the process. Multilevel-feedback queue scheduling attempts to do this by moving CPU-bound processes to queues with successively larger time quanta.