Project 1A
Terminal I/O and Inter-Process Communication

INTRODUCTION:

In this project, you will build a multi-process telnet-like client and server. Part A of the project (this part) can be broken up into two major steps:

You will be extending the same code in Project 1B, so make sure it is readable and easy to modify.

RELATION TO READING AND LECTURES:

This lab will build on the process and exception discussions in the lecture on processes and exceptions, but it is really about researching and exploiting APIs.

PROJECT OBJECTIVES:

DELIVERABLES:

A single tarball (.tar.gz) containing:

PROJECT DESCRIPTION:

You will write a program that compiles to an executable named lab1a, that accepts the command line argument --shell (explained below).

  1. Study the following manual sections:
  2. Character-at-a-time, full duplex terminal I/O

    Write a program (executable should be called lab1a) to:

    Note: You will surely have your program exit without properly restoring modes, after which your terminal session may seem unusable. Get familiar with the stty sane option of stty(1). If your program exists with your terminal modes in some unusable state, you can usually fix it by typing ^J stty sane ^J, where ^J is a control-J (or linefeed character).

  3. Passing input and output between two processes

    Extend and refactor your program to support a --shell argument to pass input/output between the terminal and a shell:

    The trick here is that will not be a strict alternation between input from the keyboard and input from the shell. Either is capable of generating input at any time. If we do a read(2) from the keyboard, we will block until keyboard input becomes available, even if there is input from the shell pipe waiting for us! The poll(2) system call enable us to solve this problem:

    You should now be able to type shell commands to your program, see them echoed as you type them, and then see the output from the shell (and any command you run under it).

    Because we have disabled all of the normal input processing, the interrupt character (^C) becomes just another character. When your program reads a ^C (0x03) from the keyboard, it should use kill(2) to send a SIGINT to the shell process. Note that the shell will not necessarily die as a result of receiving this signal.

    You may find it easier to tell if your program has recognized a ^C or ^D if, rather than echoing them directly back to the screen, you translate each into a standard graphical representation (echoing a caret in front of the letter: ^C or ^D).

    You may find debugging complicated by the fact that it is not obvious which process did or did not receive or generate which character when. If you add a --debug option to your program that enables copious logging (e.g., to stderr) of every processed character and event, you may find that this greatly facilitates the debugging process.

  4. shutdown processing:

    Note that the three normal shut-down scenarios (closing the pipe from the keyboard reader, receiving a SIGPIPE from the keyboard reader, and receiving an EOF from the shell reader) are not mutually independent. It is likely that, no matter how the shut-down is initiated, multiple of these events will occur in a non-deterministic order.

  5. error checking

Summary of exit codes:

SUBMISSION:

Your README file must include lines of the form:

And, if slip days are allowed on this project, and you want to use some, this too must be included in the README file: If, for instance, you wanted to use two slip-days, you would add the following line: Your name, student ID, and email address should also appear as comments at the top of your Makefile and each source file.

Your tarball should have a name of the form lab1a-studentID.tar.gz. You can sanity check your submission with this test script.

We will test it on a departmental Linux server. You would be well advised to test your submission on that platform before submitting it. Depending on the TA policy for your quarter, submissions that do not work on these servers may lose points.

A HISTORICAL NOTE ON CR, LF, AND EOF:

Long ago, when interaction was through mechanical teletypes with moving print-heads and paper rolls, these ASCII codes had the following meanings:

So every line of text ended with <cr><lf> or 0x0D 0x0A. This is still the case in Windows. Other people felt it was archaic foolishness to require two characters to indicate the end of line, and suggested that <lf> or 0x0A (renamed newline) should be all that was required. This is how files are represented in UNIX descendants. But when output is sent to a virtual terminal, the newline is still translated into the two distinct motion characters <cr> and <lf>.

DOS systems used to put a 0x18 (^Z) as the last character of a file to indicate END OF FILE, while most other operating systems simply ended the data (subsequent reads return nothing).

GRADING:

Points for this project will be awarded:

value feature
Packaging and build (15% total)
5% un-tars expected contents
5% clean build w/default action (no warnings)
3% Makefile has clean and dist targets
2% reasonableness of README contents
Basic Functionality (35% total)
5% correctly detects/reports bad arguments
5% correctly detects/reports system call failures
5% correctly changes console to character-at-a-time, no-echo mode
5% correctly restores terminal modes on exit
5% keyboard input echoed one character at a time
5% keyboard input written to screen one character at a time
5% correct <cr> and <lf> handling
--shell Functionality (50% total)
10% forks a process for the shell
10% correctly passes keyboard input to screen or shell
10% correctly passes output from shell to screen
5% ^D sends EOF to shell
5% ^C sends SIGINT to shell
5% correct <cr> and <lf> handling
5% report shell exit status on exit