You may do this assignment individually or in groups of two. If you work alone, you should develop your shell for Linux. If you work in a team, you should write a single program that can be compile to run either on Linux or on Windows. In either case, you should program in C. (In Windows, you should use the Win32 API not use Cygwin etc. :-))
int
main (int argc, char **argv)
{
while (1){
int childPid;
char * cmdLine;
printPrompt();
cmdLine= readCommandLine();
if ( isBuiltInCommand(cmdLine)){
executeBuiltInCommand(cmdLine);
} else {
childPid = fork();
if (childPid == 0){
exec ( getCommand(cmdLine));
} else {
if (runInForeground(cmdLine)){
wait (childPid);
} else {
record in list of background jobs
}
}
}
}
Here is a tar file that contains a Makefile that will get you started compiling on a UNIX/Linux platform. Copy the file and then execute the command "tar -xf example.tar" to unzip the contents. Then simply cd into the directory and type "make". This will compile shell.c into the executable shell. You can execute shell by typing "./shell" at the command prompt. You can remove the executable by typing "make clean". If you would like to understand Makefiles better, I have included a file funMakefile. Try "make -f funMakefile".
Here is a tar file that contains a Makefile and two programs that illustrate the use of the dup system call to support I/O redirection. Note that the file f1 is present in the directory and is needed as the input file for the forkDupExec program. That program when run will produce f2 an identical copy of f1 by forking off a new process, reassigning its stdout and stdin and execing cat.
If you are enjoying this project and would like to add more advanced features to your shell, here are some sugguestions:
Your README ( in addtion to your names, etc.) should contain a clear description of the status of each required feature. If you tackled any optional features, they should be clearly described (sufficiently that we can test them). You should also write an annotated bibliography describing sources of helpful information to which you referred (see the following for an example and guidelines on appropriate borrowing).
You should test your shell programs on the machines in the CSUG lab. In particular, you should be able to cd into your directory, type make, and then execute your shell (because that is what we will do to test it!). On Windows, we should be able to open the .dsp file and then build and execute your code. Any required settings/arguements etc. should be already set as part of the project. I recommend using a -DUNIX in the UNIX makefile and then listing WINDOWS in the Preprocessor Definition section of the Project Settings for the Windows project.
GNU history library (for the required functionality might be easier without it?)
The following functions are likely to be helpful (consult the man pages for details):
fork, exec, execvp, wait, waitpid, kill, dup, pipe, strncmp, strlen, malloc, free, getcwd, chdir , open, close, readline, gets, fgets, getchar, signal (*not* system!)
Sample Solutions: Eric Breck and Yanling Wang's shell (tar ), Omar Khan and Murali Kumar's shell (tar )