Presentation is loading. Please wait.

Presentation is loading. Please wait.

Simple Shell Due date: March 27, 2002.

Similar presentations


Presentation on theme: "Simple Shell Due date: March 27, 2002."— Presentation transcript:

1 Simple Shell Due date: March 27, 2002

2 Description a basic shell program that supports commands with < and > I/O re-direction. 3 built-in commands (pwd, cd and exit) > ./myshell % ps -ef % ls > ls.out % wc < ls.out % pwd % exit Bonus: 5% extra credit of this project for handling pipe

3 What to hand in Submit a tar file using the following command
%tar cvf p1.tar README typescript *.C *.h Makefile A README file with: Your name and your partner's name If you have not fully implemented all shell functionality then list the parts that work (and how to test them if it is not obvious) so that you can be sure to receive credit for the parts you do have working. All the source files needed to compile, run and test your code (Makefile, .c or c++ files, optional test scripts). Do not submit object or executable files. Output from your testing of your shell program. simple Unix commands built-in commands I/O redirection error conditions

4 Suggestions Two main modules Command parsing
Command execution to handle built-in cmd or forking a child process to execute other command and I/O redirection

5 Forking a child process

6 Forking a child process
#include <stream.h> #include <string> #include <unistd.h> #include <sys/wait.h> #define MAXLINE 80 #define WHITE "\t \n" #define MAXARG 20 typedef char *String; main() { int pid; union wait status; int i = 0; char cmd[MAXLINE]; String argl[MAXARG]; cout << "enter your command % "; cin.getline(cmd, MAXLINE); // fill in arguments argl[i++] = strtok(cmd, WHITE); while ( i < MAXARG && (argl[i++] = strtok(NULL, WHITE)) != NULL); // forking a child process if (fork() == 0) { // the child process if (execvp (argl[0], argl) == -1) { cerr << "error executing a given command" << endl; } else { // the parent process pid = wait(&status); cout << "the child's execution is completed" << endl;


Download ppt "Simple Shell Due date: March 27, 2002."

Similar presentations


Ads by Google