ECEn 424 Homework Set #10

Upload a pdf file containing your solutions to the problems below to Learning Suite before 11:00pm on the assigned date.

  1. Problem 8.18 from the text.

  2. Problem 424-10:
    Let's explore the overhead and behavior of the fork() function call. Click here to get a tar file with a simple program that calls fork() and that uses the time stamp counter to measure execution delay. Study the source code to see what the program does. After running "make", you can run the "forktiming" program. The order in the output corresponds to the order in which the operating system scheduled and ran the child and parent processes. Make a number of runs and see how consistent the measurements and execution order are. (The run10 script is included for your convenience -- it will run the program ten times. Typing "run10" should run the script.) Write up and submit your observations. Say something about the relative overhead of the fork() function. (Compare it to, say, disk accesses.) If you have access to a machine running a different version of the operating system, make several runs there and compare.

  3. Problem 424-11:
    Let's explore how signals and signal handlers can be used to change program behavior. First, think about the convenience of stopping a runaway program with a ctrl-c typed at the keyboard. We know from the text that ctrl-c causes a signal to be sent that can be caught. An alternate approach would be to type ctrl-z (putting the process in the background) and then using the kill program, but what if the ctrl-z is also caught? Use the information in Section 8.5 of the text to modify this source file to install handler1 to run when a ctrl-c is typed, and handler2 to run when a ctrl-z is typed. Compile and run the program to make sure your signal handlers are installed and functioning correctly. (Before doing this, you are advised to give some thought as to how you will actually kill the process! It would be a good idea to have another window open and to know how to use the "ps" command.) In your submission, include the full source code to "catchsigint.c" -- including your additions -- and include a screenshot of the program working correctly and finally being terminated. Write up a few sentences detailing what you learned from this and how you ultimately killed your program.

  4. Problem 9.12

  5. Problem 9.14

  6. Problem 424-12:
    Let's explore how one might use Linux support for user-level memory mapping to create virtual memory areas that are shared by multiple processes. Consider the source code (particularly "sharedmem.c") in this tar file. As you can see, it forks a child process, both processes call mmap for the same file, and then both modify the shared space. Run the "sharedmem" executable and think about the output. Look at the resulting contents of the "shared.dat" file. The first question you should address in your writeup is whether or not this program and the results you see conclusively show that processes can share writable data using the mmap functionality. Use the cycle counts output by this code to say something about the overhead of calling mmap. (Is the overhead higher or lower than you expected, and how consistent are the numbers from different runs?) How consistent is the execution order of the multiple processes? If one process always runs before the other on your test platform, where would you have to insert a "sleep(1)" call in the source code to get a different ordering? (Make the change to the source code and confirm that it works as you suspected.)

Clarifications

For problem 8.18, no programming is required.

For problem 424-10, no source code need be included in your submission. Just make the runs and share what you observed from the results.

For problem 9.12, no programming is required.

For problem 9.14, you'll have to read ahead in section 9.8 to learn how mmap can be used to map file contents to a region of virtual memory without explicit copies. (I apologize for this forward reference, but this is the last homework assignment, and this mmap functionality is something I really want you to see.) You may find it helpful to look at the man pages for mmap, open, and fstat. (Typing "man 2 open" gets you the man entry from section 2 of the manual.) Check out similar practice problems for useful hints. Finally, do NOT modify the file using a write function. Just use mmap() as the problem asks. The files in this tar file will be helpful.

For problem 424-12, no source code is required in your submission, but include output from at least one run of the program to accompany your explanation of what we can learn from this program and the results of running it. Rather than including source code that shows where you inserted the added "sleep(1)" function call, just describe where you put it.


Last updated 16 January 2018