fork
, exec
, and wait
NOTE: This assignment, like the other projects in this class, is due at the beginning of the class period. This means that if you are even a minute late, you lose 20%. If you are worried about potentially being late, turn in your homework ahead of time. Do this by submitting them electronically then giving the hard copy to me or the TA during office hours or by sliding it under my office door within twenty-four hours after the time it is due. Do not send assignments to me through email or leave them in my departmental mail box.
As discussed in class, part of the UNIX program design philosophy is not
to create each application from scratch but, rather, to build new
applications by utilizing existing programs. One way to tie these programs
together is to spawn off child processes using fork
and run the
programs using exec
.
One new application people might find useful, or at least fun, is a
picture sharing application. We'll call this application
PicShare
.
PicShare
will have the following basic functions:
For this assignment, we'll implement a simple version of
PicShare
. In this version, PicShare
will be
restricted to running on a single machine. A better version would allow
users to share pictures over the Internet. Also, in this version users will
have to check back periodically to see if new pictures have been made
available, whereas in a better version they could be notified
automatically. These other features could be added to a future version of
PicShare
, as you learn more about POSIX.
To implement the functions listed above, your program will present the user with a simple prompt (the main menu):
Press: C to Create a new picture. E to Edit an existing picture. P to Place the picture for viewing. V to View pictures in the viewing area. Q to Quit. Then hit Enter.
PicShare
will use files in two directories. One of these
will be the /tmp
directory (see Place and View, below). The
other will the user's picture directory. This will be specified by the
user's environment variable PIC_DIR
or, if that isn't set, will
be PicDir
in the user's home directory. If no directory is
mentioned in the description below, the user's picture directory is
assumed.
Create a new picture.
If the user chooses "C" (or "c"), PicShare
should ask the
user for a name for the new picture.
If the user simply hits return without entering a name,
PicShare
will return to the main menu given above.
If the user types in a new name and hits return then PicShare
will invoke a picture editor. This will be either the program found in the
user's PIC_EDIT
environment variable, or, if that variable isn't
set, gimp
. You should have a blank (white or black, your
choice) image file called blank.jpg
that is automatically copied
to the picture name the user specifies (with .jpg
appended to
it) and is opened when the picture editor is invoked.
If the user specifies the name of an existing picture, he or she is asked
whether or not to overwrite the exiting picture. If the user responds with
"Y" or "y", then PicShare
proceeds as above. Otherwise,
PicShare
will return to the main menu given above.
When the user exits the picture editor, the user is returned to the main menu.
Edit an existing picture.
If the user chooses "E" (or "e"), PicShare
should ask the
user for the name of the picture to edit.
If the user simply hits return without entering a name,
PicShare
will return to the main menu given above.
If the user specifies the name of an existing picture, then
PicShare
will invoke a picture editor. This will be either the
program found in the user's PIC_EDIT
environment variable, or,
if that variable isn't set, gimp
. The specified picture is
opened when the picture editor is invoked.
If the there is no existing picture with the name specified by the user, he or she will be told that and shown a listing of his or her picture directory. Then he or she will be returned to the prompt for the picture name.
When the user exits the picture editor, the user is returned to the main menu.
Place the picture for viewing.
If the user chooses "P" (or "p"), PicShare
should ask the
user for the name of the picture to place.
If the user simply hits return without entering a name,
PicShare
will return to the main menu given above.
If the user specifies the name of an existing picture, then
PicShare
will copy the picture to the /tmp
directory of the machine on which PicShare
is running. It will
name the copy of the picture <username>-picshare.jpg
,
where <username>
is replaced by the user's actual login
name. (For example, for Frank Talk from the electronic submission
directions, the picture would be named talk9876-picshare.jpg
.)
It will also set the permissions on the picture to "world readable" so that
anyone on the machine can view the picture. However, the picture should
still be writable only by the user.
If the there is no existing picture with the name specified by the user, he or she will be told that and shown a listing of his or her picture directory. Then he or she will be returned to the prompt for the picture name.
After the picture is placed, PicShare
will return to the main
menu.
View pictures in the viewing area.
If the user chooses "V" (or "v"), PicShare
should show the
user a listing of the /tmp
directory of the machine on which
PicShare
is running then ask the user for the name of the
picture to view.
If the user simply hits return without entering a name,
PicShare
will return to the main menu given above.
If the user specifies the name of an existing picture in
/tmp
, then PicShare
should display the picture
using xv
, unless there are already the maximum number of
pictures being displayed. The maximum number of pictures will be specified
by the user's MAX_PICS
environment variable or default to 10, if
MAX_PICS
isn't set or is not a numerical value. Whether or not
PicShare
displays the picture, it will immediately return to the
main menu. (Note that the user may exit xv
at any time for any
of the displayed pictures. PicShare
will need to check for the
number of pictures currently being displayed by its children, not just
the number spawned.)
If the there is no existing picture with the name specified by the user,
he or she will be told that and shown a listing of the /tmp
directory of the machine on which PicShare
is running. Then he
or she will be returned to the prompt for the picture name.
Quit.
If the user chooses "Q" (or "q"), PicShare
should quit.
Before terminating, however, it should close any pictures that are currently
being viewed with xv
.
Other.
If the user enters any value at the main menu prompt, other than those
specified above, PicShare
should display an error message, then
display the main menu again.
All of the children created by PicShare
should be created
using fork
and exec
.
You will turn in both a hard copy and an electronic copy of your assignment. You will be given instructions on how to send electronic copies. Do not send them to me though email.
Both the hard copy and the electronic copy will contain a write-up and all
source code for PicShare
. The electronic copy will also contain
the executable of PicShare
. The electronic copy of your
write-up should not be in a proprietary format (such as MS Word); it should
be either in plain ASCII text or in a portable format (such as Postscript or
PDF). Your source code should either be in a single file called
PicShare.c
or in several files that can be compiled and linked
using make
. In the latter case, PicShare.c
(or
PicShare.cxx
) will contain the function main()
and
you will include your makefile and it will be named makefile
.
Your executable code should be called PicShare
.
Your source code should be well structured and well commented. It should conform to good coding standards (e.g., no memory leaks).
Your write-up will consist of 1/2 to 1 page (roughly 80 characters per line, 50 lines per page) explaining the data structures and algorithms used in your code. This page limitation does not include figures used in your explanation, which are encouraged and may take up any amount of space. (This explanation does not remove the requirement that your code be well commented.)
You may write your program from scratch or may start from programs for which the source code is freely available on the web or through other sources (such as friends or student organizations). If you do not start from scratch, you must give a complete and accurate accounting of where all of your code came from and indicate which parts are original, which are changed, and which you got from which other source. Failure to give credit where credit is due is academic fraud and will be dealt with accordingly.
As noted in the syllabus, you are required to work on this programming assignment in a group of at least two people. It is your responsibility to find other group members and work with them. The group should turn in only one (1) hard copy and one (1) electronic copy of the assignment. Both the electronic and hard copies should contain the names and student ID numbers of all group members. If your group composition changes during the course of working on this assignment (for example, a group of five splits into a group of two and a separate group of three), this must be clearly indicated in your write-up, including the names and student ID numbers of everyone involved.
All pictures in this assignment will be jpegs, although other picture types could have been used instead.