Assignment Three: Implement a logging facility with persistent storage.

Due date: 24 April 2003 (2 weeks)

Project Overview

The purpose of this lab is to illustrate how the virtual memory subsystem can be used to represent all objects, regardless of their location or use. In this exercise you will create a file in the local filesystem (/tmp) and map it into your processes virtual memory address space. We will then leverage the fact that a file's scope extends beyond the creating process to enable concurrent sharing of this persistent storage by all current and future process that wish to use this service.

You will also continue to explore interprocess synchronization issues in this lab. You must create a file which is memory mapped by all processes and threads wishing to log status information to the logging facility. The first thread to access the logfile is responsible for initializing any data structures and 'Opening' the log file (i.e. writes a message to log). Subsequent threads will simply open the file, map the file into its virtual address space and write log messages. Pay special attention to ensuring that only one thread initializes the file and writes the 'Opening' message. Also, you must ensure that log messages from different threads do not get intermixed. You must include a utility program that prints out the log files contents and the number of active threads using the file. In general, any number of threads can be reading the log file, but only one thread is permitted to write at a time.

Programming requirements

You must write two programs:

One program checks for the existence of the log file, creates it if necessary then creates n (set using command line option) logging processes. Each process must first verify that the log file is there (it is an error if it is not there) then check to see if it is the first thread to log a message. If it is the first thread then it writes the applicable message to the file.

It must be possible to run multiple instances of this program concurrently.

All processes open the file, memory map it using mmap(2) (see example for an example of using mmap) and then takes turns logging messages to the file. Each process must log the following messages:

You must also create a utility program that opens the logfile, prints out its size, all log messages (one per line) and the maximum number of threads that simultaneously had the logfile opened and mapped into their virtual address space. If requested, the utility program must remove the logfile from the file system.

The main program must take the following parameters:

logtest [-n n] [-f /tmp/filename]
  -n n : number of child processes to create
  -f filename : file name to crate in the /tmp directory
                if not specified then create name with the
                following convention, where pid is the numerical
                process id:
                /tmp/logtest_pid.log

The utility function must take the following arguments:

logstat [-f /tmp/filename] [-r]

  where if -r is present the program must remove the logfile from the
  filesystem and if -f is not specified then the default name is used
  as described above is used.
You must use the Solaris platform and your README file must include the results of running the logstat program.

Supporting Documentation

When submitting your assignment include documentation describing your program, experimental environment, behavior you expected, behavior you observed (if they differ, why) and a description of the experiment goals (why you chose the particular mechanisms you used). Specifically, address the following:

What to Turn In

When you turn in your assignment it should include the

How to turn in

tar and compress (gzip) your files so that I can untarr and uncompress (gunzip) them on a UNIX platform. I will not grade any homework that is not in this format. To tar, compress, uuencode and email your assignment use the following command:

mkdir lastname_firstname
cp README <your files>.{c,h} Makefile lastname_firstname
/pkg/gnu/bin/tar czf lastname_firstname.tar.gz lastname_firstname
uuencode lastname_firstname.tar.gz lastname_firstname.tar.gz > lastname_firstname.uu
cat lastname_firstname.uu | Mail -s "Submit: Project 4" cs422@cec

Alternatively, if you feel really brave you can do the following:

mkdir lastname_firstname
cp README <your files>.{c,h} Makefile lastname_firstname
tar cf - lastname_firstname | gzip -c | uuencode lastname_firstname.tar.gz | Mail -s "Submit: Project 4" cs422@cec

or simply using the compress option to tar

tar czf - lastname_firstname | uuencode lastname_firstname.tar.gz | Mail -s "Submit: Project 4" cs422@cec