Description
Project Goals:
• To understand & correctly use important Unix/POSIX system calls.
• To develop a simple shell application.
• You must be able to fully explain your solution during oral examination.
Project Description:
The goal of this project is to implement a basic shell which is able to execute commands, redirect the standard input/output (stdin/stdout) of commands to files, pipe the output of commands to other commands, and carry out commands in the background.
Your shell should implement a simple REPL (read – eval – print – loop) paradigm. Your shell should use “my_shell$” (without the quotes) as prompt. At each prompt, the user should be able to type commands (e.g., ls, ps, cat) which should be executed by the shell. You can access these binaries by searching directories determined by the PATH environment variable that is passed to your shell.
As in reality, commands can have arguments that are separated by whitespace (one or more space characters). For example, if the user types cat x, your shell will need to invoke the cat binary and pass x as its argument. When the shell has received a line of input, it typically waits until all commands have finished. Only then, a new prompt is displayed (however, this behavior can be altered – see below for details).
Your shell must also be able to interpret and execute the following meta-characters: ‘<‘, ‘>’, ‘|’, and ‘&’:
(a) command ‘<‘ filename In this case, a command takes its input from the file (not stdin). Note that spacing is irrelevant in this case. For example, cat<file and cat <file are valid inputs. Also, only one input redirection is allowed for a single command. (cat <<file is invalid)
(b) command ‘>’ filename An input following this template indicates that a command writes its output to the specified file (not stdout). Again, spacing is irrelevant (see case a) and only one input redirection is allowed for a single command.
(c) ‘| ’ The pipe character allows several commands to be connected, forming a pileline: the output of the command before “|” is piped to the input of the command following “|”. Multiple pipe
signs are allowed on the command line. Spacing is irrelevant (described above).
Example:
“cat a| sort | wc” (without quotes) indicates that the output of the cat command is channeled to the sort and sort sends its output to the input of the wc program.
(d) The ampersand character ‘&’ should allow user to execute a command (commands) in the background. In this case, the shell immediately displays a prompt for the next line regardless of whether the commands on the previous line have finished).
For simplification purposes, you should assume that only one ‘&’ character is allowed and can only appear at the end of the line. Also, if the input line consists of multiple commands, only the first command on the input line can have its input redirected, and only the last can have its output redirected. In case of a single command, standard rules apply (e.g., cat < x > y is valid, while cat f | cat < g is not).
In case of errors (e.g., if the input does not follow the rules/assumptions described above, command is not found, etc.), your shell should display an error message (cannot exceed a single line), print the prompt, and wait for the next input. The error message should follow the template “ERROR:” (without quotes) + your_error_message. To facilitate automated grading, when you start your simple shell program with the argument ‘-n’, then your shell must not output any command prompt (no “my_shell$ “). Just read and process commands as usual.
Some hints:
2. If a valid command has been entered, the shell should fork(2) to create a new (child) process, and the child process should exec the command.
4. The main challenge of calling execvp(2) is to build the argument list correctly. If you use execvp(2), remember that the first argument in the array is the name of the command itself, and the last argument must be a null pointer.
5. The easiest way to redirect input and output is to follow these steps in order:
(a) open (or create) the input or output file (or pipe).
(b) close the corresponding standard file descriptor (stdin or stdout).
(c) use dup2 to make file descriptor 0 or 1 correspond to your newly opened file.
(d) close the newly opened file (without closing the standard file descriptor).
8. While the project assignment talks about system calls, feel free to use the libc wrapper functions, documented in their corresponding beautiful man pages instead.
Submission Guidelines:
• In your home directory create a folder (e.g., project1) and place README, makefile, myshell.c files (potentially, myshell.h) there. Switch to the project1 directory and execute submit1.
• A confirmation mail of your submission is sent to your account on ec440.bu.edu. You can read this mail by executing mail.
• To automatically test your solution, we execute make (no arguments will be provided to make). After make terminates, we execute the binary ./myshell for extensive testing. (Please make sure that executing make compiles your source code and generates a binary named myshell)
• In the README file explain what you did. If you had problems, tell us why and what.
• Do not forget that you must support the ‘-n’ argument to suppress the output of the shell prompt for automated testing.
Oral Examination:




Reviews
There are no reviews yet.