Example C Programs using <code>fork()</code>

# Example C Programs using `fork()`

- ex1.c, which creates a copy of itself, then both of them die.
- ex2.c, which expects a number of seconds on the command line. It creates a copy of itself, the child waits that many seconds and then dies.
- ex3.c, which expects a number of seconds on the command line. It creates a copy of itself, the child waits that many seconds and dies, the parent waits for the child to die, and then the parent dies.
- ex4.c, which expects a filename on the command line. It opens that file as stdin, creates a copy of itself, the child replaces itself with the "cat" program (thus catting the whole file), and the parent reads and prints just the first line before dying.
- ex5.c, which opens a pipe before cloning itself. The parent writes a bunch of lines to the "write" end of the pipe, while the child treats the "read" end as stdin and replaces itself with the "more" program (i.e. it runs "more" on the lines that the parent is writing).
- A single downloadable file that expands to this whole directory.

- A makefile to go with these programs.

Last modified: Mon Nov 21 14:36:25 EST 2005