UMBC CSEE |
Computer Science & Electrical Engineering
University of Maryland Baltimore County
Baltimore Maryland 21250 USA
voice: 410-455-3500 fax: -3969
|
UMBC|
CSEE
|
Project 1: InterProcess Communications Using Pipes
(c) 2000, Gary L. Burt
Assigned: 25 Sep
Due: 9 October
Project Goals
The goals of this project are to learn the basics of how a process creation,
InterProcess Communication (IPCs), file management, inheritance of files by
child processes, and to gain experience programming with UNIX processes and system calls.
The Project
You are to design and implement a simple set of processes, where a parent creates two
children. The two children are to communicate with each other via a pipe that you
have used to replace the standard input and the standard output.
Specifications
Parent Process
The parent shall do error checking and abort on any error condition after printing an
error message.
The parent process shall accept one argument from the command line,
which is the name of an ordinary ASCII text file. (This should be in argv[1].)
The parent shall create a pipe and create the two children. It shall print out
its process ID and the PID of each child. When the parent completes successfully,
it shall print out the message:
This was a successful project.
Child 1
After child 1 is created, child 1 shall close the standard in and standard out, and
shall make the standard in to be the file opened by the parent. The standard shall
become one of the parts of the pipe used for output. Since the child does not
need the other side of the pipe, child 1 shall close it. Child 1 shall then run
another program (called child1). The child1 one process shall read one line at a time
from the standard input and write it on the standard out until the end of file is
reached. At that time child1 shall terminate successfully.
Child 2
The second child shall change standard input to be the other side of the pipe and
shall close the unused part of the pipe. It shall then cause a third program
(child2) to execute. Child2 shall read one line at a time from the standard in and
print the lines on the standard output (which is the terminal). The output shall be
in the form of:
<PID> lineNr (nrBytesRead): line
An example would look like:
<10526> 0 (13): root:x:0:root
(The actual line of text from the file for this example (/etc/group) was:
root:x:0:root
Grading
Make sure you have read the general information on programming projects. Approximately
20% of your grade is for documentation, and the remainder is based on how well your
project works. You should describe your design and implementation at the beginning of
the project; this initial description is worth 15% of your grade. Describe any
non-trivial data structures you have used, and briefly say how each relevant routine
acts on those data structures. The description should be about a half-page long. Do
not ramble incoherently, and do not simply echo the specifications given here.
The standards for documentation are:
Coding Standards
Indentation Standards
You must do the project described here. Every time the requirements uses the word
"shall" is an item that you will get points for if you did it or loss points if you
did not do it! Doing some other similar or dissimilar project,
matter how difficult or clever, may be worth 0 points. This is not a group project;
please do your own work, and be careful about sharing your code. It is OK to discuss
design issues, but in your documentation, you should give credit to your sources.
What to turn in
You shall make a tar file out of your source code files, including
your Makefile. You shall mail the tar file to the TA for grading.
Hints and Tips
- To get started, you should read your text's discussion of sys calls, and then the
man pages for fork, execve, execvp, execl, dup, dup2, wait, pipe, perror,
read, gets, write, and for any string functions
you might want to use. ("man string" will bring up a summary page on the basic
string functions.)
- The functions execve and execvp take an array of strings as their
arguments. This array is similar to the argv[] array passed to C programs.
When you create this array, it is important that the end of the array is marked
with a null pointer (Not a null string!); for example if there are k string
pointers in your array args, you would set args[k]=0.
- You might need some or all of the following "include" files.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <strings.h>
- You should develop your code in a series of stages:
- Pipes and forking are probably the most difficult part of this project.
- You should be able to do this project on any system that is POSIX
compatible, including LINUX, SGIs and Sun workstations. However,
the "official" platform for this project is linux.gl.umbc.edu
- This does not need to be a long project; if you have more than about five pages of
code you might want to think carefully about your overall design.
Points to Ponder
- When the child is created, it gets a PID assigned to it. What is the PID of the
program that the child executes? Should it change or not? Did it change?
- What is the size (in bytes) of the pipe? Is it the same size on all platforms?
Why?
- What are the ramifications of redirecting STDIN and STDOUT?
- What is the problem of using gets()?
Simple Pipe Sample Program
This will be handed out in class.
UMBC |
CSEE |