Overview.
A shell is a program that repeatedly:
Details.
This project is to write an object-oriented C++ shell program. Each non-trivial object in the project should be written as a class. Your driver program for the project should be no more complicated than this:
#include "XYShell.h"
int main()
{
XYShell myShell;
myShell.run();
}
One possible breakdown of the functionality is as follows:
To execute system programs, your shell should use the fork(), waitpid(), and execve() system calls: The fork() call clones the current process to create a child process that is a complete copy of its parent. The child process should then use execve() to execute the user's command.
If no ampersand has been given on the command-line, the parent should use waitpid() to wait until the child terminates; otherwise (an ampersand was given, indicating the command was to be run in the background), it should return to the top of its loop, prompt the user, and await their next command. You may also find the sched_yield() system call to be useful in synchronizing the parent and child processes.
You should read the UNIX manual pages (section 2) for the details of the various system calls listed above, especially what header files must be #include-d to use them. There are also may be WWW tutorials/examples available that you may find useful.
To illustrate:
$ ./xyshellshould run your shell, which then displays its prompt and awaits a user command:
/home/adams/proj/shell/$When the user types a command, the program should perform that command and then prompt for the next one:
/home/adams/proj/shell$ ps
PID TTY TIME CMD
2208 pts/2 00:00:00 bash
2428 pts/2 00:00:00 xyshell
2485 pts/2 00:00:00 ps
/home/adams/proj/shell/$
If the user types a command with an ampersand, the program should
not wait before prompting for the next command:
/home/adams/proj/shell$ ps &
/home/adams/proj/shell$
PID TTY TIME CMD
2208 pts/2 00:00:00 bash
2428 pts/2 00:00:00 xyshell
2485 pts/2 00:00:00 ps
Extra Credit.
Design and build an Environment class that captures your shell's environment, so that you can run X-Window programs. When your child process invokes execve(), send your Environment class a message that returns a char** vector containing the enviroment, and pass that vector as the third argument to execve().
Plan of Action.
0. Divide the work between you and your partner. One person should be responsible for the CommandLine class and the other should be responsible for the Path and Prompt classes. You should aim to have these classes done at the end of the first week. You should work together the second and third weeks to build your XYShell class integrating the other classes.
1. The person building CommandLine should read up on argc and argv (these are covered in C++ An Introduction to Computing most C books, and a number of on-line sites), as well as the system calls that are useful for this class. Then implement the class.
2. The person building the Path class should read up on the system calls it uses. Then implement the class. Then do the same for the Prompt class.
3. Together, read up on fork(), execve(), and waitpid(). Design the algorithm for your run() method; then build your XYShell class (replacing X andY with your initials). cd and pwd are the only built-in shell commands your shell needs to recognize.
Feel free to discuss the project, the Unix manual pages, and the system calls with myself or your classmates. You are not to look at anyone else's source code.
Your program should be reasonably efficient in terms of its use of both time and space. It should also be fully documented, with an opening (header) comment that gives all of the usual information (who, what, where, when, and why), descriptive identifiers, judicious use of white space, and in-line comments explaining any 'tricky' parts.
Turn in: A project gradesheet, stapled to a script file, in which you
In order for your project to be graded, each person in your group must sign the project grade sheet, and the group must collectively indicate what "fair share" percentage of the work each person did. (If a person did their "fair share" of the work, put 100% for that person.)
Due date: Wed, Mar 28, 11:59 p.m.
Calvin > CS > 232 > Projects > 3