ISA 563: Fundamentals of Systems Programming

Spring 2013
Muhammad Abdulla
General Information | Textbooks | Schedule & Notes | Projects | Policies
Homework 3
Due: 11:59 PM, April 2, 2013 
Reminders: Follow the submission instructions. Remember to comment your code!

Total Points: 200

1) Your Shell. (200 pts)

   Shells are programs that provide a command line interface. Writing your
   own shell is a classic C exercise that serves as a good introduction to
   the C library, the system call layer, and the underlying operating
   system's process management.

   In this exercise, you will write your own shell. Your shell should have
   the following features:

     o  maintain a history of commands (up to the last 100, then age off old ones).
     o  implement the following built-in commands:
         1) pwd --- use the getcwd() function to print the working directory
         2) cd --- use chdir() to change directory to the target. If the
            target is the character '-', change back to the previous working
            directory. If the target is '.', do not change directory. If the
            target is '..' change directory to the parent directory (if it
            exists).
         3) history --- print the history of commands. For example,

            history
            1  ls
            2  cd tmp
            3  cat my.txt
            4  vim my.txt
            ...
            
     o  fork and execute a child process (a command)
            1) If the user enters an absolute path (command name starts with /),
               then your shell should try to execute it. 

	    2) If user enters a a command name alone (no forward slashes),
	       then your shell should check these directories in the
	       following order and execute the command if found:

               /bin
               /usr/bin
               /sbin
               /usr/sbin

            3) If user enters a command with a relative path (does not start
               with a /, but contains one inside the path), then your shell
               should check the path and should try to execute it from the 
               current directory. For example:

               ./myprog
               local/bin/path/myprog

            If you have an executable, myprog, under /home/user/bin, where
            you also hapenned to be, then giving

            myprog

            should fail as not found, whereas

            ./myprog

            should work as normal.

     o  implement !-based shell command recall
        (e.g., typing !20 at the prompt executes the 20th command in
         the history, if it exists. This feature should handle events
         that don't exist gracefully)
     o  add the following built-in commands:
         1) pushd --- push current directory on a stack
         2) popd --- pop this directory from the stack and chdir to it.
         3) dirs --- print the directory stack

   This assignment tests your ability to read the C library API
   documentation, design and organize a medium-size, complex C program,
   understand a C program's interaction with the OS, and design and build
   data structures (i.e., a stack) in C using structs, unions, and typedefs.
   This exercise also provides ample opportunity to test your program.

   Note that this assignment invariably results in someone "fork()-bombing"
   the machine they are developing the shell on (and endless loop where each
   child process forks() another child process that forks another child, and
   so on...). Take extreme care to avoid doing this. OS schedulers have
   gotten better at confining this type of Denial-of-Service attack so that
   it only affects the user's own slice of CPU time, but on some older OSs,
   you can still bring the machine to its knees. If you are using a shared
   infrastructure, keep another terminal window open to kill stray processes
   (using the Unix 'kill' command) and always 'nice' your shell using 'nice
   19 [cmd]'.

   This is a popular assignment, and it's likely you'll find the code for
   many shells online. I do not mind if you refer to these pieces of code for
   general design ideas and program structure.

   ******If you do so, however, please cite the location of this code
   and the author of it in your README file.******

   Keep in mind that the point of this exercise is to help you understand the
   interaction between user-level programs and the OS. Copying someone else's
   shell doesn't really assist you in fullfilling that goal.

   __________________________________________________________________________
   Note:

   You may want to consider using GNU getopt library for processing command
   line options.

     
Date & Time
bullet
bullet (EST)
What is New?
Valid W3C XHTML
© 2008-2013 Muhammad Abdulla
Last Modified: January 21, 2013