An operating system, such as Windows XP or Linux, is a set of instructions to the hardware that manages the way the computer uses such resources as processor activity, memory, storage space, I/O devices, and interaction among multiple applications and utilities running at the same time. It also presents a consistent environment for programs and device drivers, so the same programs and I/O devices can run on computers with different processors, operating speeds, and amounts of memory and storage.
More specifically, an operating system performs these tasks:
Managing the processor
Managing generic I/O devices
Providing an interface to application programs
Providing an interface to the user
In practice, most operating systems (including Windows) come with a set of additional utilities and applications that use the application program interface and device drivers that support many specific I/O devices; but strictly speaking, these programs and drivers are not part of the operating system kernel, even if they are part of the operating system package.
As the Windows Task Manager utility (see Figure 5.7) shows, the operating system can instruct the CPU to share its processing activity among several programs (or several processes within a single program) that appear to run at the same time. The Task Manager shows the percentage of the total processing time used by each program in the CPU column. The operating system acts as a broker that assigns a share of the processor's time to each program (called an image in the Task Manager) and switches among programs as efficiently as possible. If the computer has more than one processor, the operating system divides the total workload among all the available processors.
Figure 5.7: In this example, Eudora.exe is using about two-thirds of the CPU's time.
The operating system keeps track of all the programs that demand access to the processor and assigns CPU cycles to one of those programs, based on the order in which it receives the requests for access and the importance of each program. When the first program has used the amount of time assigned to it, the operating system copies and stores the current details of that program and immediately moves on to the next program in its queue. This sequence of events repeats many times every second, so it appears that all of the active programs are running at the same time.
The computer reads instructions and data from memory and stores the results of its actions in memory. It uses other parts of memory to store configuration settings, such as the number of colors used by the video display and the actions assigned to each mouse button, and other information about the current condition of the computer. So the operating system must assign a separate physical location in memory for each active program, and other programs and services that may become active in the near future.
In order to operate as efficiently as possible, the computer stores data and programs in four different kinds of memory: one or more cache memories located on the CPU chip itself, RAM mounted on the motherboard, virtual memory located on a disk drive, and long-term storage on one or more disk drives and other storage devices.
The cache memory can communicate with the processor more quickly than other types of memory. This is why the computer uses a cache controller to select and place data in the cache that it expects the processor to use in the near future.
RAM is the set of memory chips that the operating system uses as its main memory. The operating system places programs and data files at specific addresses and instructs the processor where to find them.
Windows and other operating systems use virtual memory on a disk drive as overflow for active programs and data files that don't fit in RAM. Because it takes a lot longer to exchange data with a mechanical disk drive than an electronic memory module, adding RAM to a computer often improves the computer's performance and speed by reducing the number of times the operating system has to use virtual memory; if there's enough RAM in the system to avoid overflow into virtual memory, it won't be necessary to swap data back and forth between virtual memory and RAM.
The operating system moves program and data files between the processor and the disk drives (or other storage media). It uses information it obtains from the BIOS to identify the file structure used by each drive and to store files in the format that corresponds to that file structure.
The operating system manages the exchange of input and output data between device drivers (described later in this chapter) and the CPU. It holds data from different sources in blocks of memory called buffers and relays the content of each buffer to the processor when the program or service that controls that data stream is active. When another activity takes control of the processor, the operating system continues to accept data and store it in a buffer.
Outbound data from the processor moves into a buffer, where the operating system releases it at a speed that the output device can handle. It also uses queues and buffers to hold incoming signals and pass them to the processor in an orderly manner.
An application program interface (API) is a set of generic commands and responses that the operating system uses to perform specific functions. Application programs convert inputs from outside the computer to common API commands, and standard API outputs to specific visual, audible, or other forms (such as text or pictures on a screen, flashing lights or specific sounds) within the structure of that particular program.
For example, a graphics-communications program might let a user create a network by dragging and dropping icons and connecting links in an on-screen display. The program converts the specifications of the graphic network to a set of Network Services API commands that the operating system can use to assemble the network.
The Windows API includes these categories:
Base Services: These provide access to core features of the operating system, such as memory, process and file management, and I/O devices. An application program can use these services to manage and monitor the computer's resources.
Common Controls: These allow application programs to use the same appearance and control elements as the Windows shell (the look and feel of Windows). Common controls allow a user to expect a similar look and feel in programs produced by different software developers.
Graphics Device Interface: Applications can use a consistent GDI to produce images for printers, video displays, and other devices.
Network Services: These control communication between programs on different computers through a network.
User Interface: This presents consistent visual images on the monitor, audible signals through speakers, requests for inputs, responses to mouse movement and keyboard inputs, and all the other ways that a user interacts with the computer. The Windows user interface also allows multiple programs to share the video display by placing information from each program in a separate window.
Finally, the operating system includes one or more shells that define the commands, graphic elements, and other properties of the interface between the computer and the people who use it. In Windows, the menus, the layout of the desktop, the mouse cursors, the shapes and colors of windows, and the sounds that play when certain events occur are all parts of the shell. Most people think of the operating system in terms of the user interface's look and feel, but it's often possible to use two or more very different shells with the same operating system.