Professional Documents
Culture Documents
Signals Lab
Signals Lab
1. Presentation of signals
The signals have various origins, they can be:
• Sending:
kill (num_du_processus, num_du_signal) in C,
kill -num_du_signal num_du_processus, in Shell.
Note: The sender cannot know whether the receiver has received the signal or not.
• Receiving:
Remarks :
1. On UNIXs of the Berkeley family, for example Solaris from Sun, after running the specific function
defined by the user, the default option is restored. If you want to keep the specific option, you have to recall
signal(num_sig, fonction) in function.
2. We are not allowed to change the default processing of certain signals, such as SIGKILL.
2.Ignore Signals
Write a program that ignores ALL signals. The programming scheme is given below. The role of while(1) is to loop
to wait for the reception of a signal.
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
int main(void){
int Nb_Sig;
for(Nb_Sig = 1; Nb_Sig < NSIG ; Nb_Sig ++){
...
} while(1){
sleep(5);
} /* Attendre des signaux */
return 0;
}
To do:
1. Test the return value of the signal function to identify the (rare) signals that cannot be ignored. Consult
/usr/include/sys/iso/signal_iso.h which is included by #include <signal.h> to identify the signal
according to its number (Nb_Sig).
2. Press <CTRL>C in the window where the program is running. Also send signals to this program using kill from
another terminal. Note that SIGKILL (signal number 9) terminates this program.
1. Test the return value of the signal function to identify the (rare) signals for which specific processing cannot
be defined.
2. Press <CTRL>C in the window where the program is running. Also send signals to this program using kill from
another terminal. Note that SIGKILL (signal number 9) terminates this program.