Professional Documents
Culture Documents
Forks On The Road: CSC 209H Summer 2004: Assignment 2 (10% of Final Mark) Due Date: June 23rd 2004
Forks On The Road: CSC 209H Summer 2004: Assignment 2 (10% of Final Mark) Due Date: June 23rd 2004
Your task is to write a program (a2t2.c) that downloads a set of specified files using
fork() and the wget command. The main process of your program starts by obtaining an
integer from standard input. This represents the number of file URLs that will specified
by the user subsequently and will never exceed 10. The user will enter the URLs on
separate lines and these will never exceed 100 characters each. After reading this
information into your program, the main process will fork() the same number of children
as there are files to download and waits for all of these to complete before it terminates.
Each of the child process downloads one of the files using the wget command. To invoke
a command from within your program, use the system call system(). This function
takes in a string containing a command and executes it. For example, the following call
works similarly to the previous command:
system("wget http://www.cs.toronto.edu/~iq/csc209s/uoft.gif");
Note that this task requires basic string handling that will be covered in week 5. You will
have to read and store strings from standard input. Also, you will have to create the string
that specifies the command in the system() library function call by concatenating wget
and the URL you receive from the user.
Finally, in your paper submission, answer the following four questions:
1) Consider the statement: the distributed manner in which we are downloading
files will always improve performance as opposed to the case where we download
them sequentially within the same process. Is the statement true? Explain your
answer.
2) What happens if a child process never terminates and we had use wait() in the
parent process? How can we handle this problem? (You do not have to code this!)
3) Suppose the parent created 10 processes and waited for them sequentially. That is,
wait for the first child, the second child, and so on. Just before the first child exits,
what state are the other children in when child 1 is downloading a very large file
that takes a lot of time to download while the rest are downloading small files that
download quickly?
4) If we wanted to see orphan processes, how would we modify the specification of
the assignment?
Submission
All assignments in this course require you to submit all your source code electronically.
You are also required to hand-in a printed version of your code and the testing you
performed to the TA in the tutorial when the assignment is due. Failure to follow this
may result in a grade of 0 on the assignment. A marking scheme and specific submit
commands will be posted on the website prior to the due date. In addition, we may
perform electronic testing on your program. The conventions specified in this handout
should be sufficient but keep checking the newsgroup for updates/corrections.
Enjoy!