Project 2 -- fork, exec, and wait

Due Thursday, October 17

(Note that due date is later than originally listed in the class schedule.)

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 amusing, is one that allows them to download and modify images from the web. We'll call this application PicMod.

PicMod will have the following basic functions:



The Assignment

For this assignment, we'll implement a simple version of PicMod. In this version, PicMod will be restricted to dealing with a single base picture and its derivatives at any one time and will only allow downloading of pictures. A better version would allow users to work with multiple pictures at once, to upload them to remote machines, and to process all pictures from a directory or series of directories as well. These other features could be added to a future version of PicMod, as you learn more about POSIX.

To implement the functions listed above, your program will present the user with a simple prompt:

Please enter the URL of the picture to download (the hit enter):

PicMod will check to see if the URL appears valid (we'll allow them to start with either http:// or ftp:// and contain any combination of letters, numbers, periods, and forward slashes) and appears to be for an image file (we'll allow the file extension to be .jpg, .jpeg, and .tiff, although there are, of course, many other image file types available). If either of these is not the case, PicMod should give an informative error message and prompt the user for a new URL.

If the user enters a URL that passes the checks above, PicMod will attempt to download the image file specified using wget. If wget fails to get the image file specified, PicMod should take note of this, provide the user with an informative error message and prompt the user for a new URL.

If at any time the URL given by the user is blank (the user simply hits return), PicMod should exit.

If PicMod successfully downloads the image file specified by the user, PicMod should present the user with a list of modifications that he or she can make to the image. The options presented should be all of the image-dependent scripts available in gimp on the CSN Solaris machines. To see which are available, load an image in gimp, right click on the image, and move down the menu to "Script-Fu". The options will be in the submenues below this. For example, "Add Bevel" (found under "Decor") would be an option presented to the user. The options should be presented as a simple one key choices. For example, your menu of choices could appear (in part) as follows:

    Press:
        a   Add Bevel
        b   Circuit
        c   Coffee Stain
        .   .
        .   .
        .   .
        Z   Quit
    Then hit Enter.

If the user chooses any option except "Quit," PicMod should use gimp to modify the picture as directed and save it under the file name o_<filename>, where o is replaced by the one letter option that the user chose for the modification and <filename> is the original filename for this image. If gimp fails to process the image for some reason, PicMod should provide the user with an informative error message and prompt the user with the menu of choices again.

If gimp creates the new image appropriately, PicMod should use xv to display both the original image and the modified image to the user. If xv fails to display either image correctly, PicMod should provide the user with an informative error message, close any open images, and go back to asking for a URL.

If xv displays the images correctly, PicMod should ask the user which image to modify next, based on filename. The first time through, the options presented to the user will be the original and the modified image. For example, if the original file was named mypicture.jpeg and the user chose to modify it using option c, then at this point, the user would be presented with a simple choice such as:

    Press:
        1   to modify mypicture.jpeg
        2   to modify c_mypicture.jpeg
        0   to exit
    The hit Enter.

Once the user has chosen which image to modify, PicMod should close that image, present the user with the menu of modification options again, and go through the whole process again for the image selected.

PicMod should allow the user to have up to 9 image files open at once. If the user tries to open more than 9 image files, PicMod should tell the user that he or she needs to close one of the images before creating and displaying a new (modified) image.

PicMod should also take note if the user closes all open image files. If this happens, PicMod should return to prompting the user for a new URL.

In addition, PicMod should keep track every time the user closes an image and only allow the user the option of choosing among open images to modify.

If there are any images open when the user quits PicMod, PicMod should close those images before exiting.

If the user enters any value at the menu prompts, other than those specified above, PicMod should display an error message, then display the menu again.



Notes on this assignment

All of the children created by PicMod should be created using fork and exec.



What to turn in.

You will turn in both a hard copy and an electronic copy of your assignment. Please follow the instructions on how to send electronic copies. Do not send them to my email address.

Both the hard copy and the electronic copy will contain a write-up and all source code you used in this project. The electronic copy will also contain the executable version of your code. 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 PicMod.c (or PicMod.cxx) or in several files that can be compiled and linked using make. In the latter case, PicMod.c (or PicMod.cxx) will contain the function main() and you will include your makefile and it will be named makefile. Your executable code should be called PicMod.

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 include 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.)



Other

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 or 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.

Each group member is required to contribute equally to each project, as far as is possible. You must thoroughly document which group members were involved in each part of the project. For example, if you have three functions in your program and one function was written by group member one, the second was written by group member two, and the third was written jointly and equally by group members three and four, both your write-up and the comments in your code must clearly indicate this division of labor.