labForksAndSignals

 

Due Date

See the calendar for due date.

Objectives:

Description:

Write a program that forks a second process when run. The parent should print its own PID AND the PID of the child when it is successfully forked.
The parent process should catch SIGINT and print a message to the user saying that it should be killed by SIGQUIT. If the parent receives SIGQUIT, it should send a SIGUSR2 to the child and continue executing; then the parent should terminate after it receives SIGCHLD from the child. The parent should "reap" the terminating child by handling the SIGCHLD signal, and print the status of the child that terminated. Note: It may be advisable to setup signal handlers in the parent after forking the child, else the child may inherit some signal handlers from the parent.
If the child receives a SIGUSR1, it should print its own PID and continue to execute. If the child receives a SIGUSR2, it should print its own PID and terminate.
The parent and child would normally be doing useful work while waiting for signals, but for this lab simply have each one of them calling sleep( 99999) in an infinite loop.

Requirements:

  1. flush (i.e., fflush( stdout)) after each printf() (so that I can capture the output for grading)
  2. Your program must compile and run on system64 with the following command:
    gcc -Wall --std=c11 -pedantic *.c -o labForksAndSignals
  3. Do not include spaces in directory names or file names.
  4. For full credit, the outputs needs to match (except for the PIDs and the ordering of the second through fourth lines) labForksAndSignals-answerKeyA.txt.
    For example:
    system64:~/3240/labs/labForksAndSignals-carroll $ make clean
    rm -rf labForksAndSignals
    system64:~/3240/labs/labForksAndSignals-carroll $ make
    gcc  -Wall  --std=c11  -pedantic  labForksAndSignals.c  -o labForksAndSignals
    system64:~/3240/labs/labForksAndSignals-carroll $ ./labForksAndSignals | tee labForksAndSignals-outputA.txt
    Process 15979: Parent process
    Process 15979: Going to sleep
    Process 15981: Child process
    Process 15981: Going to sleep
    Process 15979: Caught SIGINT (signal 2) (use SIGQUIT (signal 3) to kill this process)
    Process 15979: Going to sleep
    Process 15979: Caught SIGINT (signal 2) (use SIGQUIT (signal 3) to kill this process)
    Process 15979: Going to sleep
    Process 15979: Caught SIGINT (signal 2) (use SIGQUIT (signal 3) to kill this process)
    Process 15979: Going to sleep
    Process 15981: Caught SIGUSR1 (signal 10)
    Process 15981: Going to sleep
    Process 15981: Caught SIGUSR1 (signal 10)
    Process 15981: Going to sleep
    Process 15979: Caught SIGQUIT (signal 3)
    Process 15979: Going to sleep
    Process 15981: Caught SIGUSR2 (signal 12) and exiting ...
    Process 15979: Caught SIGCHLD (signal 17)
    Process 15979: Child process 15981 terminated with exit status 0
    
    system64:~ $ kill -s INT 15979
    system64:~ $ kill -s INT 15979
    system64:~ $ kill -s INT 15979
    system64:~ $ kill -s USR1 15981
    system64:~ $ kill -s USR1 15981
    system64:~ $ kill -s QUIT 15979
    
  5. Make a file named rubric-yourlastname.txt in your project directory with a completed rubric. Specify estimated points for each entry including the number of hours spent.
  6. Include a Makefile in your submission such that running make clean and make will correctly compile your code and produce an executable named labForksAndSignals.

Submission

Before submitting your lab, remove all object (.o) files (for example, with a make clean command). Make a gzipped tarball (.tgz) of the labMalloc directory (which includes all the files originally in labMalloc.tgz, your modified mm.c and your rubric-yourlastname.txt). Submit your tarball at https://3240.cs.mtsu.edu/. For further instructions, please see the Miscellaneous page.

Rubric:

Points       Item
----------   --------------------------------------------------------------
_____ / 10   Documentation (applies to new and modified files):
             All source code files (.h & .c) include file name, author, description etc.
             Functions and variables
             + All non-trival variables are commented
             + All functions preceded by brief comments
             + Comments included before major portions of code
             + Functions should be no longer than 1 page
_____ / 10   Correctly forked a child process
_____ / 20   Correctly set up signal handlers
_____ / 10   Correctly sent signal to child
_____ / 10   Correctly reaped child process
_____ / 38   Correct output (matches the format of the example & demonstrates correct execution)
_____ /  0   Compiles and runs on system64
_____ /  2   Completed rubric (estimates for each line including hours spent)
             
_____ /100   Total


_____  Approximate number of hours spent
      

Notes

  1. Start small. Write your comments first. Then, add in code and test it a little at a time. For example, create a child process and verify that it works correctly. Then, setup one signal handler and verify that it works correctly.
  2. Be sure to clean up after yourself by killing rogue processes (e.g., ps w; kill -9 APPROPRIATE_PIDS)