ECEn 324 Homework Set #6

Submit your (hardcopy) solutions to the problems below in the homework box by 5:00 PM on the assigned date.

  1. Problem 8.12 from the text.

  2. Problem 8.18

  3. 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.13

  6. Problem 9.14

  7. 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 problems 1 and 2 (8.12 and 8.18), no programming is required.

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

For problems 4 and 5 (9.12 and 9.13), no programming is required.

For problem 6 (9.14), you may want 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.

For problem 7, 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 include source code showing where you inserted the added "sleep(1)" function call, just describe where you put it.


Last updated 2 May 2013