Labs 11-12: Command Interpreters


Motivation

Perhaps the most important system program is the command interpreter, that is, the program that gets user commands and executes them. The command interpreter is thus the major interface between the user and the operating system services. There are two main types of command interpreter:

Lab Goals

In this sequence of labs, you will be implementing a simple shell (command-line interpreter). Like traditional UNIX shells, your shell program will also be a user level process (just like all your programs to-date), that will rely very heavily on operating system services to do its job, which is:

The complicated task of actually starting up the processes, mapping their memory, files, etc. are strictly a responsibility of the operating system, and as such you will study these issues in the Operating Systems course. But telling the operating system which processes to run, which files to start up as standard IO, etc. are topics of the next two lab sessions.

Starting and maintaining a process involve many technicalities (all kinds of structures, loading, etc.), and like any other command interpreter we will get assistance from system calls, such as exec, fork, wait (in other words: see man on how to use these system calls).

How are we going to study the topics? You are going to write a mini-shell: your program will invoke (with much help from the OS) another program, giving the invoked program its parameters, waiting (or not as determined by the user) for it to complete its task, managing its input/output, and so on. A complete "industrial grade" shell provides a few additional services, but the few we'll implement will demonstrate the idea nicely. Later on, in your free time, you may wish to add features, or even graphical menus with Windows-like icons (taking care not to make them too similar, so as not to get sued by Microsoft).


Lab tasks

First week: 1-6 , second week: 7-8

First, download a little file and its header with some parsing functions in it. When writing your program, your compilation line should look something like this:
gcc -o myprog myprog.c parse.c


Task 1

Task 2

Task 3

Task 4

Task 5

Task 6


Tasks for lab 12


Task 7

Task 8