Demos will be held in 1358, barring further notice.
are on Friday, February 8th. You can now sign up for one
All fifo files should be created in /tmp. If you are creating
may be more useful than man pages for some of you. Check it out.
You can safely assume that no line will be longer than 256 characters.
Make your program work on input lines of any length (for pride, not points)
Please use the mailing list
to ask questions about the project. All such questions and their responses will be logged
here. Please feel free to peruse the questions so as to get your question answered without asking us.
The sample input file has been embellished with a few extra comments. Look
A new section has been added below on "other useful library calls"; look below for details.
A new subsection called "A note about Pipes" has been added below as well.
This project serves as a basic foundation for the rest of the projects, all of which are based around the concept of building what is called a "user-level micro-kernel." More specifically, you will be building a program that acts as a kind of "operating system" to other processes, providing typical OS services such as a file system, scheduling, and the like to other processes via IPC (more details on this will be given in future assignments). Some of the code you create here may be used in these future assignments, so you should put together a reasonable design before beginning the project, and then put together as modular and robust of an implementation as you can.
This project should be done on Solaris-based machines (the Nova lab).
It is OK to develop on Linux or other Unix-based OS's, but if it does not work on Solaris, you are out of luck.
You will be required to write two separate programs. One program generates simple requests, and the other accepts these requests via IPC and then puts them into a list. The names of these two programs should be
(it is OK if the names are
for those using C++).
The first program,
should read integers from a file and communicate them to the second program,
This communication will be done by means of interprocess communication. The means of facilitating this communication will be discussed in detail in the next section. The data being extracted from the file by
should be checked for correctness. Any invalid data should simply be ignored. No error messages should be printed and the program should not terminate. The program should most definitely not crash from the introduction of such invalid data. The program should just go on to the next line of data as if nothing had happened. A sample data file is provided
When the last piece of data has been read by
the program should send an END message to
indicating no more data is to be expected.
program should accept the integers communicated from
and place them into a linked list data structure in ascending order. It should also record the time at which each integer was received. The timer should not start until the first message is received. In other words, the first message received will always be at time zero. All the other times will be relative to this. Times should be given in milliseconds. Upon receipt of the END message,
should print out the following information to the standard output:
You should NOT hard code the name of the FIFO file into your code (for more information on what this means, read the next section). Rather, both programs should accept the name of the FIFO file to communicate through as one of the command line options. This will allow us to create any arbitrary FIFO file and make your program communicate through it.
program should accept the name of the file to read data from. The following are the sample usages for both of the programs you right. Your program executables should both be named exactly as shown here:
process fifoFile dataFile
A named pipe is really just a special kind of file (a FIFO file) on the local hard drive. Unlike a regular file, a FIFO file does not contain any user information. Instead, it allows two or more processes to communicate with each other by reading/writing to/from this file.
Creating a FIFO File
The easiest way to create a FIFO file is to use the mkfifo command. This command is part of the standard Linux utilities and can simply be typed at the command prompt of your shell. You may also use the mknod command to accomplish the same thing. This command requires an additional argument but otherwise it works pretty much the same. To learn more about these commands check out the man pages on them (just type man mkfifo or man mknod at the shell command prompt). The following example shows one way to use the mkfifo command:
prompt> mkfifo /tmp/myFIFO
That's it! It's pretty simple to set a file up for FIFO. There is also a system call that allows you to do this so you can put it in a program. You can read about that on your own if you would like.
Using a FIFO File
Using a FIFO file is slightly more difficult than creating one but not much - once you get familiar with how to make system calls. Because this named pipe looks like a file, you can use all the system calls associated with files to interact with it. In particular, you can use the open, read, write, and close system calls. The following are prototypes for each of these calls as you will need to use them.
To understand better what each of the return values and parameters are for, check each of these system calls out by looking at their respective man pages. Be sure to use the 2nd level of the man pages (on Linux, type
man 2 open,
and on Solaris,
man -s 2 open,
for example); otherwise, you may see something quite different than what you expect.
To give you an idea of how all of these can work together,
is a brief snippet showing how a sender might set up a connection and send a message.
Reading from the pipe is very similar. You need to open it up, use the
call to read information, and then close the pipe when everything is finished. More details on this process can be found on-line or by browsing various man pages.
A note about Pipes
A pipe must be opened for both reading AND writing before an open on either end will return from the open call, i.e., open will wait until the connection is setup between the two processes. This info can be found in the man page for open. It can be accessed by typing '/usr/bin/man -s 2 open' or '/s/std/bin/man -A open' on any Solaris machine in the department.
The other calls necessary for this project, read and write, also behave slighly differently with FIFO's. We would recommend reading their man pages also if you are having problems.
where (username) is your login.
Obviously, you should submit all *.c and *.h files that are needed to compile your program. You should also include a README file and a Makefile for this project. Your README file should contain information about how to run your program, any known bugs it may have, and any other information that is important to your project. Your make file should successfully compile the program and create the
Also, be sure to comment your code well so that it can be easily browsed to see what is going on. Code that is excessively difficult to read will be penalized.