Professional Documents
Culture Documents
rjp
rjp
Virtual Memory
Computer memory consists of
primary memory - RAM (random access memory)
various forms of secondary (disk) storage.
rjp
rjp
Memory has a
free page
Data needed from
backing store
rjp
rjp
rjp
10
Physical memory
full again
rjp
12
rjp
13
14
Buffering
In practice I/O is usually buffered.
We don't read/write directly to the physical device,
but to a temporary storage area (the buffer).
The OS handles the interface between this buffer and
the actual physical device, transforming the data as
required and reading/writing fixed sized chunks for
efficiency.
This is referred to as stream I/O.
The user/programmer can usually ignore this, except
abnormal cases where the buffer written to fails to be
flushed/written out.
rjp
15
Buffering
rjp
16
Directories
Although the hard bit of file handling is left to the
operating system, the user/programmer needs a way
to refer to files (names)
to keep them organised (folders or directories).
Directories provide
a logical structure for users to keep their files organised,
a structure suitable for adding security instructions to prevent
unauthorised use
you can change permissions on a directory so that only you
(or your "group") can read or write to files within it.
rjp
17
I/O devices
The directory structure also provides a means
for specifying input/output devices.
On Unix the "/dev" directory contains files (try
ls /dev) but the files there correspond to
devices, not to files on the hard disk.
If you write to these files the necessary device
driver will be invoked by the operating system this is a bit of software that knows how to start
up, read and write to this particular device.
rjp
18
19
20
Unix I/O
Normally Unix programs read input from what is
called the "standard input stream" and write to the
"standard output stream".
By default, standard input will be the keyboard, and
standard output the terminal (screen). that is, the
place to read and write stuff if no other file is
specified.
By default the standard input and output is your
terminal - or the device /dev/tty.
But it is possible (and easy) to redirect standard input
and output, so that any device or file is used for i/o.
rjp
21
Redirecting I/O
To redirect standard output the ">" symbol is used.
If we use the command "ls" it outputs to the standard
output, the terminal. But we can redirect this to a file:
%pele ls > myfile
Try this, and look at the contents of the file. If you
then want to add more on to the end of the file we can
use ">>":
%pele date >> myfile
This will stick todays date at the end of your file, after
your directory listing
rjp
22
23
24
Pipes
You can also arrange for the input for one program to
come from another program. This allows us to string
together a sequence of simple commands.
Pipes ("|") are used for this. They take the output stream
of one program and connect it to the input stream of
another.
Suppose we want our friends to know what's in our
directory. We could use:
ls | mail fred
The output of "ls" becomes the input of "mail" and a mail
message is sent containing the directory listing. Try using
this approach to mail yourself todays date.
rjp
25