CSCI 343 Project 1

 

This project is a based on a simplified version of a project from the University of Wisconsin, CS 537, http://pages.cs.wisc.edu/~dusseau/Classes/CS537-F07/Projects/P1/p1.html.

 

 

You are to write a much simplified version of the Linux shell, in C, running in Linux.  Your shell should take commands, execute them and print the output, and wait for the next command.  You are to use something similar to what we did in project 2 for CSCI 243, if you took 243..  You are to fork your program, and in the child fork, get the command, and then exec it.  When the command finishes, the child dies and the parent continues forking itself again.

 

So your program should look something like:

 

setup

while (true)

{

   pid = fork();

   if (pid == 0) // child

   {

      get command

      exec command

   }

   else

   {

      wait()

   }

}

 

You should have your shell run until the user types “exit” all in lower case.  Functions that you might find useful include:

 

·       fgets

·       execvp

·       waitpid

·       strtok

 

Here is some sample output from my program:

 

don@BeagleResearch:~/courses/csci343/p1$ p1

shell 1>ls -al

total 32

drwxrwxrwx 1 don don  4096 Jul 13 20:16 .

drwxrwxrwx 1 don don  4096 Jul  1 21:57 ..

-rw------- 1 don don 12288 Jul  1 22:33 .myshell.c.swp

-rwxrwxrwx 1 don don 12912 Jul 13 20:16 p1

-rw-rw-rw- 1 don don  1830 Jul 12 15:25 p1.c

shell 2>pwd

/home/don/courses/csci343/p1

shell 3>ls

p1  p1.c

shell 4>exit

don@BeagleResearch:~/courses/csci343/p1$

 

 

Good luck and have fun!