virtual memory
and is stored in a
special area called the
swap space
. Second, for permanence, we store everything on hard
disk in user storage space. We differentiate between main memory (cache, DRAM) and
secondary storage even though both are used to store our program code and data. We will
28
◾
Linux with Operating System Concepts
discuss virtual memory in more detail in Chapters 8 and 10 and the file system in Chapters
3 and 10.
This organization of memory is known as the
memory hierarchy
. The idea is that the
CPU, when it wants something, will try the top level of the hierarchy first (on-chip cache)
and only if it fails to find what it wants will it resort to moving down the hierarchy. Moving
down the hierarchy results in slower access but a greater likelihood that what it is look-
ing for will be found because each lower level consists of a storage type that has a greater
capacity.
If, for instance, the item sought is found in DRAM, then it and its neighboring memory
locations are copied up the hierarchy. The reason to bring its neighbors is the hopes that
what the CPU is looking for now is next to memory locations storing items that the CPU
will look for in the near future. However, in copying items up the hierarchy, other items
will have to be discarded. For instance, copying some new items into on-chip cache will
require discarding items from that cache because of its limited size. So the process of mov-
ing items around in memory is something of a guessing game: can we remove items that
we do not need in favor of items we will need soon?
As mentioned above, computers have some form of memory but not necessarily all of
these forms. It depends on the type of computer. Handheld devices will often forego hard
disk storage in favor of using DRAM and in some cases, handheld devices also forego
DRAM and use only flash memory.
Another component in our computer is the I/O system. We refer to this as a single
system although in fact it is made up of numerous devices and interfaces (connections).
Collectively, the devices in the I/O system give the user the ability to interact with the
computer. The devices will include input devices like a keyboard, mouse or other pointing
device, touch screen and microphone and output devices like a monitor (possibly a touch
screen), printer, and speakers. Additionally, our secondary storage devices are part of the
I/O system as, aside from storing files, they are used for input (when we open a file) and
output (when we save a file).
So we can think of the computer as being divided into three general categories: the pro-
cessor, memory, and I/O/storage. We can also differentiate the levels of memory and storage
into a hierarchy of devices. At the top of the hierarchy are the fastest but also most expensive
forms of memory and so we limit the amount because of their expense. As you descend the
hierarchy, your computer generally has more and more because the cost per storage unit is
greatly reduced. This hierarchy consists of from top to bottom: registers, on-chip cache, off-
chip cache, DRAM, swap space, hard disk user space, network storage devices, removable
storage devices (e.g., flash drive, optical disk drive, and magnetic tape drive).
1.8.3 Software and Users
There are two additional components to any computer system, although these are not hard-
ware. These are software and people (users). The computer itself is a general purpose pro-
cessing machine. It is set up to execute any type of program. But without the program, the
computer has nothing to do. The hardware by itself has no motivation or goal. So instead,
humans run programs.
Introduction to Linux
◾
29
A program is a step-by-step description of how to solve a problem. The description must
be in a language that the computer can understand. The only language that a computer is
capable of executing is that of its native machine language. However, programmers often
write their program code in other languages and use program translation software to con-
vert their program into machine language. An example program written in C is shown in
Figure 1.18.
Without a user, there is no one or nothing to tell the computer which program to run and
at what time. Nor, is there anything to provide input or view the output. It is the user that
controls the computer. More correctly, it is the user who uses the computer. This is because
in many cases, the user makes requests of the computer. The computer does not fulfill every
request as the user must have proper access rights for the request to be carried out.
The computer system then consists of a series of layers. At the top layer is the user who
uses the computer to accomplish some task(s). The user’s interactions cause applications
software to execute. Both the user’s interactions and the applications software must access
computer hardware. The operating system acts as an intermediary between the user/appli-
cation and hardware. The operating system is itself layered with a shell for interaction,
utilities and services, the kernel, device drivers and ROM BIOS (or firmware), and the
hardware at the bottom layer (see Figure 1.2).
1.8.4 Types of Computers
Computers can vary in size, power, and expense. At the large end, we have supercomputers
which consist of dozens, hundreds, or thousands of processors combined by some internal
network. These computers, which can cost millions of dollars, are the fastest computers
on the planet. They are often used to handle computationally intensive tasks like weather
forecasting, modeling earthquakes, operations related to genetics and the human genome,
and simulating the spread of viruses to name just a few of their applications.
At the other end of the spectrum of computers are handheld devices like smart phones.
A smart phone is primarily designed to be a telephone but can run a number of other
#include
<
stdio.h
>
int main(){
int a, b, c;
printf(“Enter three numbers: “);
scanf(“%d %d %d”, &a, &b, &c);
if(a
>
b&&b
>
c)
printf(“%d is the greatest\n”, a);
else if(b
>
a&&b
>
c)
printf(“%d is the greatest\n”, b);
else
printf(“%d is the greatest\n”, c);
return 0;
}
FIGURE 1.18
Simple example C program.
30
◾
Linux with Operating System Concepts
applications (apps). Typically, the smart phone stores the apps in a small internal memory.
The processor of the smart phone is one that contains technology of perhaps 10–15 years
earlier. Because of these limitations, smart phones often can only handle one or perhaps
two applications at a time. Additionally, to permanently save information recorded on a
smart phone, you will have to transfer it to another computer. Slightly more capable than
the smart phone are tablet devices.
In between the two extremes of handheld devices and supercomputers are the personal
computers: laptops and desktops. This type of computer will contain several storage devices
including an optical disk drive and an internal hard disk. You can also connect external
disk drives to the device and for desktop units, additional internal devices such as a second
hard disk or a floppy disk drive.
More sophisticated than the desktop computer is the server. The idea behind the server
is that it is a networked computer that services requests of other networked comput-
ers. The server might provide file storage for a few dozen computers or it might handle
HTTP requests over the Internet (a web server) or it may send and receive email mes-
sages. Depending upon the number of expected users, a server may have similar comput-
ing power and main memory as a desktop computer, or it may require faster processing
and more memory.
For instance, a file server which is utilized by no more than 10 users may not require
a superior processor. On the other hand, some types of servers are expected to perform a
good deal of processing. Web servers for large websites for instance must execute server
side code. A web site like Google would use high-end servers which contain much more
powerful processors than what you will find in a desktop computer. What is certain though
is that a server will utilize a greater amount of disk storage than a desktop computer and it
is likely that a server might have dozens of hard disk drives.
There are also computers that fall between the supercomputer and the server: main-
frame and minicomputers. These computers are more historically interesting as they
were the only platform of computer available in the first few decades of computer usage.
The mainframe and minicomputer category consists of computers expected to handle
the processing duties of dozens or hundreds of users at a time. With the inexpensive
availability of personal computers though, mainframe and minicomputer usage is far
less common.
Table 1.2 illustrates some of the characteristics of each of these types of computers. It
should be noted that these values tend to change rapidly in the computing field. The values
shown in Table 1.2 are estimates from 2013. The breakdown of computer types as shown
in Table 1.2 are not precise. You might notice for instance that high-end mainframe com-
puters and low-end supercomputers are the same. We might think of this grouping as one
class of computer which ranges at one extreme from computers worth $100,000 to those
that are worth tens of millions of dollars. We tend to see the greater expense as we add
more processors (from dozens to thousands) and as we increase the amount of DRAM and
storage. Similarly, the laptop and desktop computers run together. Laptops can have just
as great an amount of DRAM, processor cores, and storage space as a desktop computer.
About the only two aspects that are clearly different between the two types of computers
Introduction to Linux
◾
31
is the laptop is built to be portable and so is lightweight and compact, and the desktop,
because it is larger, can have a greater number of devices inside (additional disk drive units)
or connected to it (e.g., external keyboard and speakers).
1.9 THIS TEXTBOOK
Linux (and Unix) textbooks generally fall into two categories. There are users guides that
are less textbook oriented and more “how to” texts. These are fine if you already know
something about Linux and want to become more of an expert, or alternatively want to
learn enough to use the operating system. What they fail to do is teach you underlying con-
cepts; the “why” instead of the “how.” The other category of book is true operating system
concept books that might spotlight Linux or Unix with one or a few chapters dedicated to
these operating systems.
The book you hold in your hands is somewhat unique in that it combines both styles of
textbooks. This book does teach you the “how” of Linux but also emphasizes the “what”
and “why” of the operating system.
Additionally, Linux (and Unix) textbooks tend to focus on either teaching you how to use
the operating system or teaching you how to administer the operating system. This textbook
TABLE 1.2
Characteristics of Computers (as of October 2013)
Do'stlaringiz bilan baham: |