ECE231 Project 4: Signals

Due March 14, 2002

In this project, you will write a program that will both send and receive/handle Unix signals. You will run two copies of the program simultaneously. The following project requirements will describe the execution of your program:

  1. The first program copy (called P1) to start will put its process ID as ASCII text in a file called "sig1.pid" in the current directory. The second program copy (P2) will put its PID in "sig2.pid" in the current directory. You must figure out how to arbitrate access to these files (hint: look at the flock() or lockf() function).
  2. Set up signal handlers for SIGUSR1, SIGUSR2, and SIGINT as described below.
  3. In an infinite loop, do the following
    1. Busy wait for about a second
    2. Generate a random number between 0 and 1. If that number is less than 0.25, send a SIGUSR1 to the other process.
    3. Sleep for a second.
    4. Generate a random number between 0 and 1. If that number is less than 0.25, send a SIGUSR1 to the other process.
  4. If your program receives a SIGUSR1, it must do the following, but they must NOT occur in the signal handler. The signal handler only notifies therunning program to to them.
    1. Send a SIGUSR2 to the other program.
    2. Print that it got a SIGUSR1
  5. If your program receives a SIGUSR2, it must print that it received a SIGUSR2, but do not perform I/O in the signal handler.
  6. If your program receives a SIGINT (Control-C), it must disable the trapping of SIGINT (to avoid an infinite loop) and send a SIGINT to the other program. Next, it cleans up after itself by deleting its PID file. Then it exits immediately.

To turn in this project, send your program source code and a typescript of about 20 or 30 seconds duration to prasad@dream.eng.uci.edu with a subject line: ECE231_Project4 student_id