CS 284 Operating Systems
Programming Assignment #4
Due: 9/12/2001 - Class Time
You should review in the man pages
Write a C program (Prog4a.c) that mimics the program cat. i.e.
while (not EOF of stdin)
scanf(the content of stdin)
printf(everything read by scanf)
Write a C program (Prog4b.c) that will accept command line arguments of the
following types
ShellPrompt> Prog4b Prog4a
- this means that Prog4b should fork() and exec(Prog4a).
- Prog4b should wait() for 4a to exit() before it exit()s
ShellPrompt> Prog4b Prog4a < fileABC
- prior to the step #2, 4b should
- open fileABC for input
- modify the fd-Table such that 4b will scanf fileABC as stdin
- 4b should fork() and exec(4a).
- 4b should wait() for 4a to exit() before it exit()s
ShellPrompt> Prog4b Prog4a < fileABC > fileXYZ
- prior to the step #2, 4b should
- open fileABC for input
- modify the fd-Table such that 4b will scanf fileABC as stdin
- open fileXYZ for output
- modify the fd-Table such that 4b will printf fileXYZ as stdout
- 4b should fork() and exec(4a).
- 4b should wait() for 4a to exit() before it exit()s
ShellPrompt> Prog4b Prog4a > fileXYZ
- prior to the step #2, 4b should
- open fileXYZ for output
- modify the fd-Table such that 4b will printf fileXYZ as stdout
- 4b should fork() and exec(4a).
- 4b should wait() for 4a to exit() before it exit()s
=================================================================
NOTEs:
- The shell will want to interpret the '<' and '>' as file redirection
requests that IT should carry out. Prevent the shell from doing this by either
escaping them as \> and \< or quoting them as '>' and '<' or quoting
the entire command line argument.
- You may surround the operators (< and >) with spaces.
- You may assume that Prog4b will always see argv[1] = Prog4a
- You may dispense with the command line arguments completely and let Prog4b
- Read a line
- Carry out the fd manipulation, fork, exec, wait
- Go back to #1
You should use the 'script' command to capture all necessary information for
handin.