Programming Unix

Assignment 3
Semester 1, 2003

Due date

This assignment is due by 5pm, 6 June at the end of week 13.

Introduction

This is an exercise in concurrent processing and inter-process communication using pipes.

This assigment replaces the shell program written for assignment one with a version in C. Some of the deficiencies of the shell version can be addressed by the C version.

Specification

A simple version of the algorithm for assignment one is


(echo ".
.."
ls) | java -persistent ListSelect |
while read file
do
    if [ -d "$file" ]
    then
        cd "$file"
        $0 &
        cd ..
        continue
    fi

    case "$file" in
        *.class) xterm -e java `basename $file .class` &;;
        *.java)  (emacs "$file"; javac $file 2>&1 | java Cat) &
    esac
done

You should write a program in C to implement the above algorithm, with one change: the algorithm above starts a new process for the program which will use a new copy of ListSelect and show the new directory in a new window. Instead of this, continue with the same processes, change to the new directory and cause the existing ListSelect to refresh with the contents of the new directory, so that no extra windows are created.

ListSelect can be made to clear its contents by sending the "clear screen" character ^L, followed by a newline.

Hints

Instead of ls, use C code to list the directory and send this by a pipeline to ListSelect. Keep this pipeline open to send ^L and a new directory listing when appropriate. At the same time, use another pipeline to read from ListSelect.

Use execl to invoke java ListSelect, emacs and xterm.