Computer Science 322
Operating Systems
Mount Holyoke College
Spring 2008
Lecture 18: Unix Systems Programming Wrapup; Deadlock
Date: Friday, March 28, 2008
Agenda
Announcements
CPU scheduling simulator - demonstrate them!
Shell lab - don't let yourself be stuck for long - ask!
Scheduling issues over the next couple weeks (see schedule page)
Unix Systems Programming
Pipes
Another interprocess communication mechanism
Powerful command-line tool:
|
Unnamed pipe created with
pipe(2)
fd[0]
is the "read end",
fd[1]
is the "write end"
these are file descriptors
Named pipe created with
mkfifo(1)
or
mkfifo(2)
part of the file system
Duplicating file descriptors
dup2(2)
: reroute things intended for one file descriptor to another
redirect existing file descriptors (0=stdin, 1=stdout, 2=stderr)
hook the output of one pipe to the input of another
Other useful C tips and tricks
gcc -Wall
debuggers: gdb, ddd
initialization of memory (or not)
string manipulation: see
string(3)
memory management:
malloc(3)
,
free(3)
- no garbage collector here!
"object oriented" C programming
Deadlock
Idea
Necessary conditions: mutex, hold and wait, no preemption, circular wait
Resource allocation graphs
Prevention
Lecture Assignment
SG&G 7.1
A system has two processes and three identical resources. Each process needs a maximum of two resources. Is deadlock possible? Why or why not?
Examples