6.097: OPERATING SYSTEM ENGINEERING
Fall 2002
Lab 6
Hand out date: Monday November 18th
Due date: Monday, November 25th (Exercises 1-3)
Due date: Thursday December 5th (Exercise 4)

1. Introduction

In this lab, you will write a shell and a few user applications. You will extend your kernel to accept keyboard input and then use all of the framework built up in previous labs to implement a shell and small set of user-space utilities. We have provided a basic specification for the shell and user-space utilities --- however, you have the option of extending your operating system and shell to provide additional functionality.

Unlike previous labs, this lab is a team assignment. Teams should consist of two (2) people. Each team should send one e-mail to 6.097-staff@pdos.lcs.mit.edu stating the members of the team by Wednesday, 20 November 2002.

This lab is also due in two parts --- the first part is due on November 25th. The final part is due on December 5th. Note also that a TA check-off is required (see below; additional details to follow).

2. Hand-in Procedure

  1. Put your answers to the exercises in ossrc/lab6_answers.html (do not link to any external files).
  2. When you are finished coding and answering questions, make a hand-in tarball.
    athena% cd ~/6.097/ossrc
    athena% gmake handin
    .
    .
    .
    athena% ls -l handin6.tgz
    
  3. Make this file web accessible then send email containing a URL in the Subject line. Your email will be processed automatically, so be certain to follow this format.

    A fool-proof way to accomplish this is to use the following command:

    athena% mhmail 6.097-handin@pdos.lcs.mit.edu -subject http://web.mit.edu/PATH/TO/handin6.tgz -body empty
    

Check-off: As the culmination of a term of work, each team should schedule a brief meeting with one of the TAs to demonstrate the full functionality of their shell. More details will be sent out on this later.

3. Getting Started

You should now download the code for the lab. Many files are absent from this tarball and must be copied form your lab 5 solutions.

Be careful not to overwrite your lab 5 solutions.

athena% add gnu 6.097 sipb
athena% cd ~/6.097
athena% mv ossrc lab5-solutions
athena% wget http://pdos.lcs.mit.edu/6.097/labs/lab6.tar.gz
athena% gtar -zvxf lab6.tar.gz
drwxr-xr-x cates/wheel       0 Sep 15 19:34 2002 ossrc/
drwxr-xr-x cates/wheel       0 Sep 15 19:34 2002 ossrc/kern/
drwxr-xr-x cates/wheel       0 Sep 15 19:34 2002 ossrc/kern/inc/
-rw-r--r-- cates/wheel    2528 Sep 14 17:00 2002 ossrc/kern/inc/asm.h
.
.
.
athena% cp lab5-solutions/kern/locore.S ossrc/kern
athena% cp lab5-solutions/kern/trap.c ossrc/kern
athena% cp lab5-solutions/kern/pmap.c ossrc/kern
athena% cp lab5-solutions/kern/env.c ossrc/kern
athena% cp lab5-solutions/kern/sched.c ossrc/kern
athena% cp lab5-solutions/kern/init.c ossrc/kern
athena% cp lab5-solutions/kern/syscall.c ossrc/kern
athena% cp lab5-solutions/kern/inc/syscall.h ossrc/kern/inc
athena% cp lab5-solutions/user/simple/* ossrc/user/simple

4. Exercises

Exercise 1: Keyboard driver

A keyboard driver has been added to the file kern/console.c. You should read the code and hook it into the system, so that your OS can read and process keyboard input.

Next, you should extend the driver so that it buffers keyboard input in the kernel, in a small buffer. Then, you should make the keyboard accessible to user space by adding a system call that dequeues characters from this buffer.

Exercise 2: Basic Shell

Edit the code under user/simple to be basic shell. Your basic shell should read a command from the keyboard, then fork() and exec(). The shell should wait until the program exits before attempting to print the prompt again.

You should be able to type "ls" into your shell to run the program in user/ls.

You should also implement the "ls" program, so it actually lists the contents of the disk.

Exercise 3: Shell with Argument Passing

Now, extend your basic shell so it passes arguments to the programs it runs. You should also write an "echo" program in a new directory: simple/echo. follow Makefile conventions of exemplified by simple/ls.

 
$ echo aaaa bbb ccc    d ee fff
aaaa bbb ccc d ee fff
Questions:
  1. How long approximately did it take you to complete Exercises 1-3?

Exercise 4: Shell pipelines

In this exercise, you will implement the pipe command line character ('|'), which connects the output of one program into the input of another.

Here are some examples which your OS should support.

  1. $ ls | cat -n
         1  kenv0
         2  simple
         3  ls
         .
         .
    
  2. $ ls | cat -n | cat -n | cat -n | cat -n | cat -n | cat -n
         1     1     1     1     1     1  kenv0
         2     2     2     2     2     2  simple
         3     3     3     3     3     3  ls
         .
         .
    
  3. $ cat | cat -n
    hi
         1 hi
    
  4. $ cat | cat -n | cat -n | cat -n | cat -n | cat -n | cat -n
    hello
         1     1     1     1     1     1  hello
    goodbye
         2     2     2     2     2     2  goodbye
    
  5. $ echo a | cat -n | cat -n | cat -n | cat -n | cat -n | cat -n
         1     1     1     1     1     1  a
    
  6. $ echo a | cat -n | cat -n | cat -n | cat -n | cat -n | echo hi
    hi
    

You are given the freedom to implement your code however you like so long as the examples listed above run correctly. We layout one possible solution below; you can take it or leave it.

A possible strategy would be to follow a UNIX-like implementation with file descriptors and pipes. (This strategy is outlined in the lecture notes for the first lecture of the term).

The file descriptors will allow programs to abstract above the actual sources or destinations of data. For instance, in certain of the examples a program's input was the keyboard and in other cases it was from a preceeding program on the command line. Similarly, a program's output could be sent to the screen or to another program.

Type man 2 pipe on Athena to find out more about pipes.

Questions:
  1. In two pages or less, describe the interface you have specified for handling user input (if it has changed) and the design of your pipe implementation.
  2. How long approximately did it take you to do this lab?
This completes the lab.

Extra Credit

If you choose to implement any of these suggestions, please describe them briefly in your lab6_answers.html file under a separate section.


Version: $Revision: 1.3 $. Last modified: $Date: 2002/11/17 23:21:02 $