In the introduction, we saw that two of the main purposes of an operating system are to provide an interface between the hardware and the application programs and to manage the various pieces that make up a computer. To be more precise, these pieces are called resources. A resource is "any object which can be allocated within a system" [Balci 1996]. Some examples of resources are processors (CPUs), input/output devices, files, and memory (RAM). Thus, we can restate the purpose of the operating system in terms of resources. The operating system manages resources (resource allocation) and provides an interface to resources for application programs (resource abstraction).

The problem of resource allocation can be quite complex. If a computer only needs to run a single program, then every resource can be allocated to that program. However, this situation is not very realistic. Most computers, even personal computers, run several programs at once. In this situation, it is much more efficient for a computer to share its resources rather than dedicating all the resources to any single program until it finishes execution. You might think of this situation as similar to a spoiled child who has many toys and refuses to share them with other children. Although the child cannot possibly play with all the toys at once, the child keeps them all while the other children wait (and most likely cry). In this realm, the toys represent the available resources, and the children represent the programs that need to use those resources. The best solution is to distribute the toys among the children so that each child is occupied at the same time. Similarly, the operating system in a computer has various strategies for distributing resources to programs.

The applet below illustrates the problem of allocating limited resources. In the applet, you will have the responsibility for allocating and deallocating resources in a nursery of six babies. The resources are toys, blankets, and nurses. Each baby will indicate its need for a resources at various times by crying. You can allocate and deallocate resources by pressing the appropriate buttons underneath each baby. Once a baby has been allocated a resource, it will use that resource for a random amount of time, and finally return to a normal state in which the resource is no longer needed. At this point, you should deallocate the resource so that other babies can use it. Alternatively, the baby may request another resource in which case you should deallocate the unneeded resource and attempt to allocated the request resource. The effectiveness of your resource management is measured by the cumulative unhappy time of the babies in the nursery (i.e., the amount of time the babies are crying). To begin, press the "Start" button at the bottom of the applet. Note that pressing the "Stop" button will abort the current simulation rather than pausing the game. You may also set the game parameters using the drop-down boxes at the bottom of the applet.

Only slightly less challenging than the problem of appeasing a nursery full of babies is the problem of resource allocation in computers. Some resources, like the ones in the applet above, can only be shared through time-multiplexing, that is, each program receives control of the resource for a certain period of time. Other resources, like RAM, can be shared through space-multiplexing. In this case, each program receives a certain amount of the resource which it can use. Nutt [1997] explains:

"Space-multiplexed means that the resource can be divided into two or more distinct units of the resource. Different executing programs can be allocated exclusive control of different units of a resource at the same time. Memory and disks are examples of space-multiplexed resources. Time multiplexed means a resource is not divided into units. Instead, a program is allocated exclusive control of the entire resource for a short period of time. After that time has elapsed, the resource is deallocated from the program and allocated to another. Time-multiplexing is used with the processor resource."

In addition to the responsibility of resource allocation, the operating system is also responsible for resource abstraction. Resource abstraction is the process of "hiding the details of how the hardware operates, thereby making computer hardware relatively easy for an application programmer to use" [Nutt 1997]. One way in which the operating system might implement resource abstraction is to provide a single abstract disk interface which will be the same for both the hard disk and floppy disk. Such an abstraction saves the programmer from needing to learn the details of both hardware interfaces. Instead, the programmer only needs to learn the disk abstraction provided by the operating system. Nutt [1997] gives the following illustration of the value of resource abstraction:

"Suppose a programmer is writing an application to analyze stock market trends. The effort to design and debug code to read and write information to/from a disk drive would represent a significant fraction of the overall effort. The skill and experience required to write the software to control the disk drive are not the same as that to design the stock analysis portion of the program. While an application programmer must be aware of the general behavior of a disk drive, it is generally preferable to avoid learning the details of disk input/output. Abstraction is the perfect approach, since the application programmer uses a previously implemented abstraction to read and write the disk drive. A disk software package is an example of system software. Programmers can focus their attention on the application programming problem rather than diverting it to tasks not specific to the application domain. In other words, system software is generally transparent to the end user but is of major significance to the programmer."

Resource abstraction has its tradeoff, however. While making the hardware easier to use, resource abstraction also limits the specific level of control over the hardware by hiding some functionality behind the abstraction. Since most application programmers do not need such a high level of control, the abstraction provided by the operating system is generally very useful.

References