13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

52 Time Management Chapter 23.4 CountermeasuresA user who knows what policies a particular operating system uses can sometimes usethat knowledge to achieve an unfairly high level of service. For example, some operatingsystems allow a user to have many processes at the same time. A user can circumventthe scheduler’s attempts at fairness by building many processes, each of which is treatedas an independent and equal contender for the computation resource. One common formof this trick in the Unix operating system is to create a ‘‘background’’ process that executessome time-consuming operation, like a compilation, while the user interacts with atext editor to prepare some other program. (We discuss this idea in more detail inChapter 9.)A scheduler can institute a policy that lumps together all processes that belong tothe same user, giving each one less time in proportion to how many belonging to thatuser are in the ready list at the same time. The processes in wait lists do not contribute tothe load, so they may be ignored for this purpose. The Utah Tenex scheduler makes useof a fancy version of this algorithm that includes a suffering function.If the scheduler follows a policy that favors short processes, the user can programprocesses to do only a small bit of computation before artificially pausing for a very shorttime. For example, the process can periodically write a single character to the terminal.When the process returns from the wait list, it is treated by the short-term scheduler as anew arrival. New arrivals are assumed to be short. On some interactive operating systems,the user can benefit by repeatedly interrupting the process by using a keyboard‘‘interrupt’’ key, then allowing the process to continue. To prevent such abuse requiresthat the scheduler treat processes returning from interrupt wait or transput wait in thesame way as it would if they had continued computing. Such special treatment can becumbersome to implement.A similar situation arises under PSPN. Instead of submitting a long process, onecan break its work into many small pieces. Each piece will have a very high priority,since it takes almost no time. The total missed time will then be very short, although thestartup and termination expense for all the processes may be large.Some schedulers, such as the one for CTSS (the Compatible Time Sharing System,an early interactive operating system at MIT), give poorer service to processes thatrequire a large amount of main store. When such schedulers are used, programmers tendto concentrate their data and instructions, leading to less easily maintained and morebug-prone programs.3.5 Guiding principlesHow is one supposed to sift through our list of policies to pick the one that is best in aparticular case? Here is a rule of thumb: Preemption is worth the extra switching cost.Since context must switch at every interrupt from the running process back to the kernel,it does not usually cost much extra for the kernel to make a decision and allow a differentprocess to run. Clock devices are almost universal these days, from mainframe computersdown to board-level microcomputers.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!