5570: Advanced Unix Programming
Midterm review
Note:
You are responsible for learning material from the
reading assignments, class notes, examples, and programming
assignments. I give below some important topics that you should pay
particular attention to. I have also listed some questions in
here. That does not mean that these questions will appear directly in
the exam. You need to understand the issues addressed by these
questions, and be prepared to apply this understanding in different
situations too. Of course, not all the topics mentioned below may
appear in the exam, and there may be questions from topics not
mentioned below.
- C and related features
-
- You should be able to program in C.
- Makefiles: you should know the material discussed in class, and in
the examples. In particular, (i) you should be able to create targets
and dependencies, first compiling object files, and then linking them
together. (ii) You should know how to use macros, for example define
CC as gcc. You need not learn about inference rules.
- Compiler: You should know the -g, -c, -o, -O[n], -l, -I, -L, -Wall, -ansi,
-pedantic, and -D options to gcc. (You need not learn about -pg and
feedback optimization for the exam; however, you may find these
useful in real life.)
- Header files: You should know what pre-processing is, how macros are
preprocessed, about guards, errors that can happened due to incorrect
macro use, C linkage in C++ programs, incorrect header files use
(for example, defining global variables or functions in the header
file). (You may also want to learn about disadvantages of
pre-processing, and alternatives to its features. This is not be
required for the exam, but may be useful in real life.)
- You should be able to implement features based on HW 1, such as
reading a line at a time, command line arguments (including
converting the command line argument strings to int and long), and
obtaining the value of an environment variable.
- Some useful functions, such as sprintf, sscanf, strcpy,
strcmp, atoi, atol, system, malloc, free, etc.
- Portability: Problems that can occur due to different sizes of
integer types, little-endian vs big-endian, how you can find out if
a machine is little endian or big endian, POSIX standardization and
_POSIX_SOURCE macro.
- Introductory material on Unix API
-
- How to set environment variable on the command line, in Bourne and
C shells, how to get the value of an environment variable from a
program, using getenv().
- Exit status, the difference between exit and _exit.
- Process ID, getpid, getppid, realize that the ps command
presents the process IDs too.
- User ID, real versus effective user ID, saved-setUID, how
these are set on exec (you can ignore group ID), getuid/setuid (you
can ignore the case of processes running with super-user privilege).
- errno
- Note: You need not memorize which header file is to be used for which system call!
- Unix File system
-
- Concepts of file, directory, link, file name, inode, and
symbolic link, the technique of 'unlink'ing a temporary file
immediately after creating it (AUP page 140).
- Some questions: What is the difference between a soft link and a
hard link? Does the i-node store a file name? What operations are
involved in moving a file? Is the i-node deleted if a soft link is
deleted? Is an i-node always deleted immediately after the last link to it
has been deleted? Do names belong to links or to files? What
happens on renaming a file? When can a file be deleted?
- File access permission, ownership of new files and directories
(ignore the group ID issue).
- File I/O
-
- File descriptors and open file description, which file descriptors
are used for stdin, stdout, and stderr respectively, were are the file
offsets and the file sizes stored, how does this affect appending to
files, can multiple file descriptors point to the same open file
description, can multiple processes point to the same open file
description, can multiple open file descriptions point to the same
inode, order of file descriptors on opening files.
- Some questions: What is the difference between a file
descriptor and an open file description? Is there a unique open
file description for each file? Is there a unique open file
description per process, for each file opened by that process?
Can multiple processes point to the same open file description?
Are there distinct offsets available for reading and writing, or
is there only one file offset? Does the file offset belong to the
inode, or to an open file description, or to the file descriptor?
If two different open file descriptions point to the same file,
then are their offsets kept equal?
- Process management
-
- fork, what does it return, how do you distinguish between parent
and child, what is duplicated on the child, what happens to file
descriptors, is there any relative order of execution, is the
memory of the parent and child shared, or is it just copied once (and
then remains distinct), sec 8.3 and fig 8.1 are particularly important.
- exit and wait, how can you determine the exit status and
whether the child exited normally, will code after the exec
statement be executed if the call is successful, what if the call
was not successful, what happens to the process's data after
calling exec, what about the file descriptors, learn about the
FD_CLOEXEC flag.
- Idea behind the exec family of commands, execv.
- Some questions: What happens to the file descriptor after
forking? If one of the processes closes one end of the pipe, will the
other process still be able to use it? Similarly, what happens
after an exec? What is a race condition?
- Pipe
-
- pipe, is a pipe available to the child too, if you fork and then
create a pipe, then will that child have access to the pipe, is there
a limit to the pipe size, implementing pipe in a shell,
- Some questions: Which command is used to create a pipe? What
is the argument to the pipe() command? Can we pass an int * as
argument, without allocating memory for it -- why or why not?
Which end is used to write? Which end is used to read?
- Signals
-
- What is a signal, what are the possible signal dispositions (catch, ignore,
default action), signal(), which signal does Control-C send, can
SIGKILL be caught or ignored, can SIGINT be caught or ignored, what
happens after a signal is caught, SIG_IGN and SIG_DFL macros, learn
that the signal function can cause the handler to be erased after
each invocation, what can go wrong with this scheme?, what happens
to the signal masks and dispositions after exec, what happens in
the child (after the parent forked it), what happens to pending
signals -- for forked process and exec-ed programs.
- sigemptyset, sigfillset, sigaddset, sigdelset, sigismember,
sigprocmask, sigaction, sigpending, SIG_BLOCK, SIG_UNBLOCK,
SIG_SETMASK, sigprocmask, what is the difference between the effect of
SIG_BLOCK and SIG_SETMASK, does the old signal mask give the
signals that are blocked, or those that are unblocked, sigset_t type.
- sigaction, struct sigaction and its fields: sa_handler, sa_mask,
sa_flags, do not set the sa_sigaction field to 0!, semantics of
sigaction.
- kill, what does it do, can it be used to send signals only to
related processes, what does the alarm system call do, note the
difference between the latest POSIX definition, and what the book
mentions about the POSIX definition when pid==-1.
- Some questions: What is a signal? Why is the ANSI signal
function considered unreliable? What happens after a signal is
caught? What is the typical effect of an uncaught signal? Do
identical blocked signals have to be queued according to POSIX,
and are they usually queued? Is the type of signal caught included
in the signal mask for the duration of the the signal handler by
default (with sigaction), Is the signal handler reset to the
default action, after each invocation of the signal handler (with
signal? with sigaction?)? What happens to "slow" system calls
that are interrupted by a signal? (Read the POSIX standard, in
particular, the SA_RESTART flag under sigaction. You need not use
this flag, but it will help you learn about what the standard
requires.) What do the terms 'generate', 'deliver', and 'pending'
mean, in the context of signals. What does kill do? What arguments
should be provided to the 'kill' function? Can you "kill" someone
else's processes, normally? Can you kill any of your processes, or
should the process sending the signal be a relative of a process
it tries to 'kill'? What does the 'alarm' system call do? What
happens if a signal is caught in the 'read' system call, when you
are trying to read from the terminal? What if you were reading
from disk?
- Be prepared for questions related to HW2 too.
- Look at the example programs.
- Review quiz questions, and other issues I mentioned in class as important.
Last modified: 27 Sep 2002