Fall 2002
Instructor: Ashok Srinivasan
Lecture 7
Acknowledgements: The syllabus and power point presentations are modified versions of those by
T. Baker and X. Yuan
Announcements
Reading assignment
APUE Chapter 3
Pages 47-56, 56-62
APUE Chapter 5
Section 5.4 is particularly important
APUE Chapter 7
Section 7.3 is important
You should know the material from 7.1, 7.2, 7.4 7.9
from previous courses and classes
APUE Chapter 8
Sections 8.1-8.3, 8.5-8.6, 8.9-8.10
You should also understand the idea behind race
conditions
Review
UNIX file system
File system abstraction
Directories
File descriptors
Week 3 Topics
UNIX file system
File system abstraction
Directories
File descriptors
HW1 hints
I/O redirection
Process management
fork, exit, wait, waitpid, execv
Pipes
Named and unnamed pipes
Implementing pipe in a shell
Direct I/O
Using open()
The usual C-language stream-oriented I/O
operations, like printf(), use buffers and process
data character-by-character
They are implemented using the lower-level direct
I/O operations read() and write()
In situations where we do not want to view the
data as characters, or where we want greater
efficiency, it is better to use the direct I/O
operations
Using man
Look at the man page for write()
If there is more than one page on a given name, man will
give you the one that is first in the chapter order of the
Unix manual.
Shell commands are in Section 1, I/O and OS interface
calls are in Section 2 and Section 3 respectively
Example Programs
example1.c illustrates a common
programming error
Failure to provide the correct number of
arguments to a vararg function
File I/O
File descriptors
open, creat, close, dup, dup2
I/O redirection
File descriptors
Implication of the file descriptor/open file
descriptions/inode table organization in UNIX
open and creat
search for the first empty slot in the process file
descriptor table
allocate an open file description in the file table, which
has a pointer to the inode table
See example3.c
I/O redirection
All UNIX processes have three predefined
files open
stdin -- STDIN_FILENO (0)
stdout -- STDOUT_FILENO (1)
stderr -- STDERR_FILENO (2)