Homework 1 Due Wednesday, April 16 Directions for submission: Make directories ProblemI and ProblemII, and put the relevant files in each: ProblemI will contain a LaTeX file Solution.tex. (Show your work!) ProblemII will contain two or more C source files and a Makefile. Make a README file which gives the names of all people in your homework group. Use tar to combine README, ProblemI and ProblemII. Then gzip and uuencode, and e-mail the result to the TA I. (Review of probability concepts.) A. Antonia and Po possess coins whose probability of heads is p and q, and toss them n times, resulting in X and Y heads, respectively. Find the EXACT value (NO integrals) of P(X > Y) in terms of p, q and n. [Hint: First review P(X = k), especially the reasoning behind it. Then try finding P(X > Y) for n = 4. Then do the general case.] Use the "capital sigma" notation for expressing your sums; in LaTeX this is the \sum construct. B. Suppose a random variable has the density 2x on the interval (0,1), 0 elsewhere. Find P(X > 2/3) and E(X). II. In this problem, you will write a program similar to ftp. You will actually write a pair of programs, named dtp and dtpd, corresponding to ftp and ftpd. The program dtp will fetch an entire directory tree which is rooted at the directory specified on the user's command line. (Note: The full path must be specified in that command-line argument, not just a relative path.) The program dtp will copy all files and directories in the entire directory tree, i.e. including subdirectories, subsubdirectories, and so on, setting up the same tree, rooted in the directory from which dtp is invoked. (The action in terms of directory trees will be similar to `tar' and `cp -r'.) The form of the command line is dtp For example, on my machine, heather.cs.ucdavis.edu, I might type dtp sgi8.cs.ucdavis.edu /home/matloff/Pub/152A to copy the given directory tree from sgi8. The program dtpd is intended to run constantly on machines which offer dtp access; in your testing, of course, you will run it on one machine and invoke dtp from another. [Be sure that it is another machine, especially a different architecture, though you are allowed to skip the DECs :-) .] The dtpd program does not need to handle more than one request at a time. Do not worry about the file permissions in the files created on the client side. As in all assignments, you must follow specified requirements exactly. In particular, the following are REQUIRED: * Your programs must be written in C (not C++). * You must supply a Makefile, which produces both dtp and dtpd. (And the two executable files must have these names.) * You must use the system calls opendir(), readdir() and stat(); the first two are used to determine which files are in a given directory, and the third will be used to determine which of those files are directories. (I've placed a sample program, LS.c, in the same directory as this homework file, showing how to use these system calls.) * You must use recursion to descend through the directory tree. * You must use sockets for the transfers between machines, using TCP. You should be able to use the example from our handout in class as a guide for this. Note: Do not use port 2000; if everyone uses it, you can imagine the chaos that would result. * Do NOT use any calls to system(). For example, call the function mkdir(), instead of something like system("mkdir x"). (For details on the function, type "man mkdir" on an SGI machine, and go all the way to the end.) In this and all other homework assignments, "must" means "must"; "required" means "required". So for example, you cannot use the "tar" command to package a directory; that would be inconsistent with the requirements given above. HOMEWORK THAT DOES NOT COMPLY WITH THE REQUIREMENTS WILL NOT RECEIVE CREDIT. You may find that your programs dtp and dtpd work on "smaller" problems but not on larger ones, say directory trees with a large number of levels, in which case you may exceed your limit of file descriptors. If this happens, don't worry about it. Note that the handout with the sample socket programs mentioned that in some cases multiple calls to read() on a socket will be needed to get all the data produced by one write() on the other end of the socket.