Hardware Reference
In-Depth Information
allocating and freeing data structures on one or more heaps. Heaps are used for
storing data structures that are dynamically created and destroyed. The heaps are
not garbage collected by the operating system, so it is up to language run-time sys-
tems or user software to free blocks of virtual memory that are no longer in use.
(Garbage collection is the automatic removal of unused data structures.) Heap
usage in Windows 7 is similar to the use of the
malloc
function in
UNIX
systems,
except that there can be multiple independently managed heaps.
The heart of any operating system is providing services to user programs,
mostly I/O services such as reading and writing files. Both
UNIX
and Windows 7
offer a wide variety of I/O services to user programs. For most
UNIX
system calls,
Windows 7 has an equivalent call, but the reverse is not true, as Windows 7 has far
more calls and each is far more complicated than its
UNIX
counterpart.
UNIX I/O
Much of the popularity of the
UNIX
system can be traced directly to its simpli-
city, which, in turn, is a direct result of the organization of the file system. An or-
dinary file is a linear sequence of 8-bit bytes starting at 0 and going up to a maxi-
mum of typically 2
64
1 bytes. The operating system itself imposes no record
structure on files, although many user programs regard ASCII text files as se-
quences of lines, each line terminated by a line feed.
Associated with every open file is a pointer to the next byte to be read or writ-
ten. The
read
and
write
system calls read and write data starting at the file position
indicated by the pointer. Both calls advance the pointer after the operation by an
amount equal to the number of bytes transferred. However, random access to files
is possible by explicitly setting the file pointer to a specific value.
In addition to ordinary files, the
UNIX
system also supports special files, which
are used to access I/O devices. Each I/O device typically has one or more special
files assigned to it. By reading and writing from the associated special file, a pro-
gram can read or write from the I/O device. Disks, printers, terminals, and many
other devices are handled this way.
The major
UNIX
file system calls are listed in Fig. 6-35. The
creat
call (with-
out the
e
) can be used to create a new file. It is not strictly necessary any more, be-
cause
open
can also create a new file now.
Unlink
removes a file, assuming that the
file is in only one directory.
Open
is used to open existing files (and create new ones). The
mode
flag tells
how to open it (for reading, for writing, etc.). The call returns a small integer cal-
led a
file descriptor
that identifies the file in subsequent calls. When the file is no
longer needed,
close
is called to free up the file descriptor.
The actual file I/O is done with
read
and
write
, each having a file descriptor
indicating which file to use, a buffer for the data to go to or come from, and a byte
−