6.1 INTRODUCTION
Operating systems are an important component of computer systems. In this section, we study some of these algorithms.
Some of the algorithms for operating systems considered in this section are:
References for these and other related algorithms are given at the end of the section.
6.2 VARIOUS OS ALGORITHMS
Election
A network of processors has to solve a problem for which a certain coordination is needed. Many distributed algorithms require one process to act as coordinator, initiator, sequencer, or otherwise perform some special role. This unique processor known by all the others and that typically, knows the others, coordinates the work of the others by assigning them sub-tasks. This coordinator will act as the leader who distributes to the processors under its coordination some information defining the status of the problem to be solved.
Election algorithms are for electing a coordinator. If all processors are exactly the same, with no distinguishing characteristics, there is no way to select one of them to be special. Consequently, it is assumed that each process has a unique number, for example its network address. In general, election algorithms attempt to locate the process with the highest process number and designate it as coordinator.
Furthermore, we also assume that every process knows the process number of every other process. What the processors do not know is which ones are currently up and which ones are currently down. The goal of an election algorithm is to ensure that when an election starts, it concludes with all processors agreeing on who the new coordinator is to be.
Producer Consumer
Generally there are two entities in Producer-Consumer algorithm: Producer - an entity that generates data,
Consumer - an entity that uses the data that was generated.
There always is a relationship between these two entities as they have to know about the state of each other, e.g. producer has to know, when a consumer is free to consume data, thus it is allowed to generate data. At the same time consumer has to know, when new data has been produced so consumer could consume it.
Algorithms: An Approach Using Puzzles and Brainteasers Operating Systems
In real life it often happens that producers and consumers have different efficiencies. It is usually not a problem if consumer is highly efficient, as there is less data loss during data consumption (consumer consumes data when it is produced, and does nothing, when there is nothing to produce). However if producer is more efficient than consumer, then there is potential problem with loss of data as the consumer is given too much data with which to work. In this case some sort of storing device should be used, e.g. a buffer (or a queue). When some data is produced and no consumer is available, then that data goes to the buffer. When the consumer becomes available, the next piece of data it will consume will be the one from the buffer.
The most common real-life example of the Producer-Consumer algorithm is a process, called print spooling. Print spooling refers to putting jobs(in this case documents that are about to be printed) into a special location(buffer) in either computer memory, or hard disk, so that a printer could access this document whenever the printer is ready. There are couple of advantages of spooling. First of all the printer can access data from the buffer at any rate that is suitable for the printer. Secondly the work of computer is not interrupted while printing, thus a user can perform other tasks.
As it was mentioned mentioned above, producer and consumer have to know about the state of each other, so they would know when each one of them can produce/consume. If we have one producer and consumer, what would be the producer-consumer algorithm, so both would know when it is possible to producer/consume and when one of these should wait? HINT: Incorporate some sort of wait/signal messages so producer and consumer would inform each other when they are ready for production/consumption.
Round Robin Scheduling
A round robin is an arrangement of choosing all elements in a group equally in some rational order, usually from the top to the bottom of a list and then starting again at the top of the list and so on. A simple way to think of round robin is that it is about "taking turns." Used as an adjective, round robin becomes "round-robin."
In computer operation, one method of having different program process take turns using the resources of the computer is to limit each process to a certain short time period, then suspending that process to give another process a turn (or "time-slice"). This is often described as round-robin process scheduling. In sports tournaments and other games, round-robin scheduling arranges to have all teams or players take turns playing each other, with the winner emerging from the succession of events.
A round-robin story is one that is started by one person and then continued successively by others in turn. Whether an author can get additional turns, how many lines each person can contribute, and how the story can be ended depend on the rules. Some Web sites have been created for the telling of round robin stories by each person posting the next part of the story as part of an online conference thread.
Other algorithms for which interactive applets are available at www.algana.co.uk are: Banker
Bully
Priority Scheduling Resource Request Virtual Memory Clock
6.3 CASE STUDY
The “Design and Implementation of an Educational Java Module” senior project of Hassan Chahrour (2006) provides an interactive module for use in an algorithms course (see figure 7).
Figure 1. A screen shot of the final running program (resized).
Treating this project as a case study, analyse the module design and adapt it to include the following operating systems algorithms:
(i) Banker (ii) Bully (iii) Election
(iv) Priority Scheduling (v) Producer Consumer (vi) Resource Request (vii) RR Scheduling
Algorithms: An Approach Using Puzzles and Brainteasers Operating Systems
6.4 BIBLIOGRAPHY & REFERENCES
1. http://www.algana.co.uk/Algorithms/OperatingSystems/OSFrameset.htm
2. http://www.cwu.edu/~cs_dept/hilights.html
3. http://www.cis.ksu.edu/~dan/despot/pdpta01.pdf 4. http://www.cs.nott.ac.uk/Seminars/seminars_2003.htm
5. http://www-db.stanford.edu/people/hector.html
7. SEARCHING