Week 6

Processes, Inter-Process Communication (IPC) and Sockets PROCESSES AND THE RUDIMENTS OF IPC It's essential that you understand something about processes and how Unix manages them. I'm having you do some activities to go along with your reading for processes, but nothing that you will turn in. READ: Molay. 8.1-8.4.5 ACTIVITY: I want you to run every one of the example programs listed in the book in order to aid your reading. These are: exec1.c psh1.c forkdemo1.c forkdemo2.c forkdemo3.c waitdemo1.c waitdemo2.c You can transcribe the code out of the book, or you can copy and paste from the Molay website here: http://wps.prenhall.com/esm_molay_UNIXProg_1/7/2041/522502.cw/index.html SOCKETS: Sockets are a mechanism for doing IPC over a network connection. PLEASE follow my suggested strategy for reading each of the following sections: READ: 11.5.1 READ: 11.5.2 -- some of the examples related to telnet won't work due to the rapidity with which internet security has become an issue. If you want to try out the time server example though you can telnet to time.nist.gov and it should work. READ: 11.5.3 READ: 11.5.4 - This shows a huge code example that sets up a socket, waits for a connection, sends data and closes. I recommend doing the following: in the code there are comments that clearly state each step of the process. Once you've read the code for one step, read the explanation of it on the pages that immediately follow the code. IMPORTANT NOTE: You need to make one modification to the code in 11.5.4 to get it to work: In "step 2" of the code comment out the line that reads: bcopy( (void *)hp->h_addr, (void *)&saddr.sin_addr, hp->h_length); Replace it with the line: saddr.sin_addr.s_addr = htonl(INADDR_ANY); This allows the socket to listen for incoming connections from any internet address - the other way would work, but this way is more flexible and will make testing easier. READ: 11.5.5 You should of course compile and run the code from 11.5.4. Be aware that you have to start running the server and put it in the background, that what this does: %> ./timeserv& It fires up your timeserv program but the puts the process in the background and returns the shell to you. To test it locally you may have to do one of several things: For example if you run the timeserver on port 13000 you can try: %> telnet localhost 13000 or %> telnet 127.0.0.1 13000 or %> telnet 13000 READ: 11.5.6-11.5.8 Follow the same advice for the programs in these sections. Compile the code and test it (I might suggest actually writing one out by yourself) and MAKE SURE YOU UNDERSTAND all the steps involved. EX1: Write a socket client server program that does the following: SERVER: Your server will provide a text-chunk-lookup service. The server has a set of text documents (keep them all in one dir). The server waits for the client to send a string of text (representing the text-chunk to lookup). The server determines if that string of text appears in any of the text documents. If the chunk appears in some document or documents, the server sends back a colon-separated list of the names of the files it occured in. If the chunk does not appear, the server should send back some string indicating the chunk was not found. CLIENT: The client program should be an interactive terminal interface. It should repeatedly ask the user for a string of text to lookup. It connects to the server, makes the request, gets the result from the server, displays the result, and closes the connection. HINTS AND ASSUMPTIONS: 1. In the interest of getting things done, you may assume that every chunk will be a six-word chunk. That will allow you to pre-process the text files. (If you want more of a challenge then don't make this assumption). 2. You may do the sever work in whatever way you find easiest. For example, you may want to pre-process the text files to make one big chunk-file with a consistent format, like this: chunkOfTextFromSomething:nameOfFile anotherChunkOfTextFromBlah:nameOfFile 3. You may want to check out the 'system' call (man 3 system) if you want to leverage any parts of the unix OS for text processing. That will only get you so far though. REQUIREMENTS: The server and client should accept command-line args for the servername and/or portnumber to connect to. Thus, for local testing, firing up the server might look like this: %> ./myChunkServer 11217& and firing up the client then might be: %> ./myChunkClient localhost 11217
How to Submit