CSC 213, Fall 2008 : Schedule : Lab 4


Lab 4: Signals and Timers

Goals: This lab exercise provides experience with system timers and signals.

Reading:

Collaboration: You will complete this lab in teams, as assigned by the instructor.

Basic Problems:

Guidelines:

Part A

In 1 and 2 below, you will operate quicksort on random integer arrays of sizes 100000, 200000, 400000, 800000, 1600000.
  1. As a base line, a first program should set the three timers indicated above, perform a quicksort, and retrieve processing times in a single-process environment. This program should not include any fork or signal calls. Also, timing should not include the time required to initialize the array.

    This program may perform the timing, quicksort, and printout for a single array size, with the program rerun for each of the array sizes given above. Alternatively, the program may call the timing, quicksort, and printout steps within a loop to handle all array sizes with a single execution of the program.

  2. Modify signal-1.c, so that the child process computes the amount of time required for each quicksort that it performs. The parent process should do no work, but should print its own timings for each period of time that the child spends computing. In other words, both the parent and the child should run all three timers for the quicksort. As with the baseline program, timing should not include the time required to initialize arrays.

Part B

In this part, you should sort one very large array (it should take at least 45 seconds to sort).

Note: you may need to use malloc(2) to allocate this array from the heap, since it will likely be too big to be allocated from the stack.

  1. Modify program A.1 to include two special signal handlers.

    Your user interface need not be extravagant or "overly" robust. It need only work correctly when the user enters properly formatted input, taking some default action otherwise. You may use any of the I/O functions you choose.

    Update: Your modified program does not need to use any timers to keep track of the total time for the sort, as in A.1. You need only implement the signal handlers and set an appropriate timer.

  2. SIGINT handler behavior:

    1. What happens when you type Ctrl-C once?
    2. What happens when you type Ctrl-C twice (ie, the second Ctrl-C happens while inside your signal handler)? Give your explanation.
    3. What would you like to happen if someone typed Ctrl-C while in your signal handler? Why? Explain how you think you could make this happen.

  3. SIGALRM handler behavior:

    1. What happens when it takes longer than the timer length to answer (i.e., what happens after you finally do answer?) Give your explanation.
    2. What would you like to happen when it takes someone longer than the timer length to answer? Why? Explain how you think you can make this happen.


Work to be turned in:

You may turn in both part A and part B on Friday, 9/26 if you prefer.

Follow the submission guidelines for both parts A and B. For each program, use the script command to list the program and to execute one or more test runs for the required array sizes. In your commentary explain any differences in results that you see for different array sizes and configurations of processes.


Jerod Weinman

Created June 24, 2008
Based on CSC 213, Fall 2006 : Lab 4: Signals and Timers
Last revised June 24, 2008
With thanks to Henry Walker and Janet Davis.