Lab Assignment--Signals
Lab Code
To get the sample and exercise code, please use the following commands in your cs330 directory:
curl -O -s https://www.labs.cs.uregina.ca/330/Signals/Posix/Lab10.zip
unzip Lab10.zip
(Please do this lab on os1 or os2)
Part 1: Questions
Write the answers to the following questions as comments at the beginning
of your code.
- The notes for this lab state that each signal has one of four default actions (not
including continue):
- terminate (or exit)
- core
- stop
- ignore
Use the signal man page to find one signal that corresponds to each of these four actions.
Find signals other than SIGILL, SIGHUP, SIGWINCH, and SIGSTOP.
-
For which two signals can you not change the default action?
Part 2: Code
Write a program that forks a child process. The parent will send SIGWINCH to
the child. The child will override the default action of SIGWINCH so that
a message is displayed and the child exits. Without using wait(),
the parent will exit after the child has exited.
(Note: automatically, when a child exits,
a SIGCHLD signal is sent to the parent)
More Details:
- Child will:
- Overwrite the default action of SIGWINCH
- Loop infinitely and print a message "child waiting".
Please note that you will want to introduce a little
delay in your loop. Otherwise, you will get too many
messages. Hint: Try nanosleep with a value of 5000L instead
of 500000L
- Parent will:
- Overwrite the default action of SIGCHLD
- nanosleep for 500000ns as in:
nanosleep((const struct timespec[]){{0, 500000L}}, NULL);
- Send a SIGWINCH to the child
- Loop infinitely and print a message "parent waiting".
Please note that you will want to introduce a little
delay in your loop. Otherwise, you will get too many
messages. Hint: Try nanosleep with a value of 5000L instead
of 500000L
- You only require one handler for SIGWINCH and SIGCHLD. It will:
- Print the numeric value of the signal received
- Print a message that the child or parent received the signal
- exit
Sample run for the code:
% a.out
child waiting
child waiting
child waiting
child waiting
child waiting
child waiting
child waiting
...
child waiting
child waiting
child waiting
child waiting
child waiting
child waiting
Signal Received 28
parent waiting
...
Child received signal
parent waiting
parent waiting
parent waiting
parent waiting
parent waiting
parent waiting
parent waiting
...
Signal Received 17
Parent received signal
Deliverables:
- Answers to the two questions
(as comments at the beginning of your code)
- The code for Part 2
- A sample run