You decide to improve upon the UNIX Command Interpreter V1. Your goals in doing so are as follows:
To gain more experience with UNIX process creation and management.
To gain experience with UNIX low-level file I/O, including file
descriptors, duplicating file descriptors, redirecting input and output,
and pipes.
To learn more about UNIX programming, including environment variables.
Program requirements for your shell
Your shell must handle the following:
- Standard commands from V1:
- Run no-frills commands
- Exit by typing "exit" or <CTRL->D.
- Change directories using the "cd dir" command..
- All system calls must correctly handle possible failure. If a failure
occurs, the program must deal with it in a reasonable fashion.
- Set programs to running in the background. As soon as the command has been started,
the shell issues a prompt to the user and is ready to process the next command.
Syntax: command &
Test line: $ sleep 60 &
Man pages: none really needed. Just don't wait for child/children.
- I/O redirection.
- UNIX pipes (just single stage pipe -- you may implement multiple stages if you wish)
Syntax: command | command
Test line: $ ls -sF | grep /
Man pages: pipe, dup2.
- Redirect standard output to file truncating destination file.
Syntax: command > output_file
Test line: $ ls -sF > junk
Man pages: open(2), close, dup2.
- Redirect standard output to file, appending to data in destination file.
Syntax: command >> output_file
Test line: $ ls -sF >> junk
Man pages: open(2), close, dup2.
- Redirect standard input from file.
Syntax: command < input_file
Test line: $ od -c < junk
Man pages: open(2), close, dup2.
Sample code to handle redirection and code for
pipes.
- The parent shell should ignore the SIGINT (^C) and SIGTSTP (^Z) signals
generated from the keyboard.
However, the child processes should ignore SIGTSTP but show default
behavior (eg, die) for the process interrupt signal (SIGINT).
Test line: $ (type ^C's and ^Z'sat the prompt -- should get ignored)
Test line: $ sleep 60<CR> (then type ^Z; sleep should ignore it. Type ^C; sleep should die and return you to the prompt.
man pages: go with signal (2). Don't mess with sigaction() unless you have some
genuine extra time on your hands.
Sample code to handle signals.
Due date and deliverables
- Due midnight, Monday Feb 17, via the electronic submission system.
Submit under "P2 - Shell V2".
- Submit the directory with your source code and executable. Please call the
primary source code file "shell2.c" and the executable (your command interpreter)
"a.out" to make it easier for the grader to identify them.
|