Project 2 -- fork(), exec(), and wait()

Electronic Copy Due Tuesday, October 16, 1:00pm

Hard Copy Due Tuesday, October 16, 1:30pm

NOTE: This assignment, like the other projects in this class, is due at a particular time, listed above. This means that if you are even a minute late, you lose 20%. If you are worried about potentially being late, turn in your project ahead of time. Do this by submitting it electronically before it is due and giving the hard copy to me during office hours or by sliding it under my office door before it is due. Do not send assignments to my personal email address. Do not leave hard copies in my departmental mail box or attempt to give them to departmental staff (who cannot and will not accept them).

As discussed in class, one way to build an application is to use existing applications that each do a part of the job you want your new application to do, then tie them together and add whatever additional functionality is needed to make the whole system work. Imagine, for instance, that you want to have a system that allows you to download your images from a server where you have them stored, add a watermark to them, then upload them to the server again. You could, of course, do all of these steps manually using existing software but that would be tedious if you had many files to watermark. You could also build this from scratch, writing your own software to download and upload sets of files, add watermarks, and verify the results in a browser, if you had the time. Alternately, you could using existing download/upload, image manipulation, and web browsing programs, and tie them together with fork(), exec(), and wait(). Because the latter approach is much less work, it is the approach you will take in this assignment.

In this assignment, you will take the first step toward the development of a batch image watermarker. This is only the first step, since you have not yet learned in this class about mechanisms for passing the input and output of processes to one another (although you will!), you have not yet learned in this class about mechanisms for reading directory entries (although you will!), and you are not assigned the job of creating a nice GUI front end for your watermarker (since that is a topic for another class). Still, it will let you gain experience with the basic mechanisms for using other applications to accomplish goals for your new application.



The Assignment

You are to create a program called wm to carry out the download, watermark, upload, and verify steps for a single file at a time. (In the next assignment, this will be expanded to carry out this process for multiple files in a "batch processing" way and will be called bmw.) The user will invoke mw as follows:

wm URL WMFILEPATH
Here, URL is expected to be the URL of a single image file in a common format, rather than a web page or directory, and WMFILEPATH is the path to the watermark file. (Your program should be able to handle at least png, jpeg, and tiff image file types for both the image to be watermarked and the watermark itself.) When run, wm will do the following:
  1. Download the file at URL to the present working directory.
  2. Watermark the downloaded file using WMFILEPATH as the watermark.
  3. Upload the watermarked image back to URL.
  4. Display URL in the user’s preferred browser. To determine the user's preferred web browser, wm should look at the BROWSER environment variable. If BROWSER is NULL or unset, wm should consider this a display failure.
  5. Exit with values as follows: 0 for successful completion, 1 for download failure, 2 for watermark failure, 3 for upload failure, and 4 for display failure.



What to Turn In

You will turn in both a hard copy and an electronic copy of your assignment. Electronic copies must be submitted to the appropriate drop box in D2L for the course. Do not send them to my email address.

Both the hard copy and the electronic copy will contain a cover sheet documenting group membership and contributions (see below), all source code you created for wm and a write-up 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 explanations, which are encouraged and may take up any amount of space. (The explanations do not remove the requirement that your code be well commented.)

The electronic copy will also contain an executable for wm which should be called wm.



Important Notes

Your source code must be written in C or C++ and must compile using gcc or g++ on the CSN Linux computers. For creating new processes, changing the executable, and checking on the progress of child processes, your code must use fork(), exec (that is, any of the exec family of system calls), and wait (or waitpid), respectively. Your code should be well structured and well commented. It should conform to good coding standards (e.g., no memory leaks).

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 cover sheet (see below), including the names and student ID numbers of everyone involved and details of when the change occurred and who accomplished what before and after the change.

Each group member is required to contribute equally to each project, as far as is possible. Your cover sheet 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, your cover sheet must clearly indicate this division of labor.

Note that all personally identifying information (names, student ID numbers, 4x4s, etc.) must only be included on the cover sheet and nowhere else in the project materials.

For the various functions that your program must carry out, I recommend that you explore wget, composite, and/or sftp.