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.
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.
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:
"Main program thread [parent id:process id], begin new logging event at [timeofday]"
This thread then creates n logging processes and waits for them to terminate. When all logging processes terminate the main process (i.e the parent) writes the following message to the log file:
"Main program thread [parrent id:process id], end logging event at [timeofday]"
"First process [parrent id:process id], concurrent process number %d, memory mapped file at [time of day]"
then the thread must sleep for 10msec. The remaining processes log the message:
"Other Thread [parrent id:process id], concurrent process number %d, memory mapped file at [time of day]"
where %d just means to write the integer value that this process set the active concurrent process count variable.
"Thread [parent id:process id], concurrent process number %d awake at [timeofday]".
The thread then must decrement the active concurrent process count (stored in the log file) and exit.
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.
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