COS 421 Program 1 - UNIX Command Interpreter (V1)

You have just had the wonderful insight that the interface to the operating system could be nicer than what is currently available with punch card sets. New technology -- called "terminals" and "terminal emulators" -- could be used to write a program (you decide to call it a "command interpreter", or maybe just a "shell" because that is shorter) that interacts in a friendly fashion so as to allow you to simply type in commands and have the operating system jump to carry out those commands.

You decide to write the shell in two steps. The first version of the command interpreter (V1) will let you explore the basic ideas and make sure that you've got the hang of this "programming UNIX" stuff. Later, you will work on a fancier version.

Your goals for the first version of the command interpreter are as follows:
  • To get better acquainted with UNIX.
  • To get a feel for system tool/application level programming.
  • To gain experience with UNIX process creation and management.

The program requirements for your shell

You decide that your shell will exhibit the following behavior:
  1. To exit the shell, you can type either <CTRL-D> at the beginning of a line (that's how UNIX simulates end of file from keyboard input) or "exit".
  2. Run standard UNIX commands just like the regular shell (bash, sh, csh, etc.)
    Syntax: command [option ]*
    Test command: $ ls -sF file1 file2
    Man pages: fork, execvp, wait and waitpid.

    NOTE: you must use fork and execvp, as well as your choice of wait or waitpid. Using execvp requires that you build an argument vector à la argv for the new process.
    Be very careful to use fork( ) properly. The correct use will be explained in class. If you mess up on this, you will quite possibly tie up/lock up your account until a snickering (or after the fourth time, grumpy) sysadmin cleans up the mess. Do take the warnings seriously and follow instructions carefully.

  3. Change the current working directory.
    Syntax: cd path_to_new_directory
    Test command: $ cd /
    Man pages: chdir.

Groups

You decide to work on this in groups of exactly 1 people :-). Seriously, this is a great time to get going on brushing up you 'C' skills, reading "man" pages, and generally getting in shape for the semester. Group programs will come later.

Suggested reading

  • Ch 1.3-4

Sample code

Due date and deliverables

  • Due midnight, Monday Feb 10, via the electronic submission system. Submit under "P1 - Shell V1".
  • Submit the directory with your source code and executable. Please call the primary source code file "shell1.c" and the executable (your command interpreter) "a.out" to make it easier for the grader to identify them.