Upon receipt
ignore the signal | signal(signal_number,SIG_IGN) |
reset default treatment | signal(signal_number,SIG_DFL) |
define specific treatment | signal(signal_number,function) |
see /usr/include/sys/signal.h or /usr/include/bits/signum.h or /usr/include/sys/iso/signal_iso.h for a list of signals.
Write a
program that ignores all signals. The skeleton is given below. while(1)
is there to wait forever for signals.
#include
<signal.h>
void
main(void)
{
int Nb_Sig ;
for (Nb_Sig = 1; Nb_Sig <
NSIG ; Nb_Sig ++)
{
***
}
while(1); /* wait for signals */
}
TO
BE DONE::
Modify the previous program in order to execute the Traite_Sig function when receiving a signal.
The skeleton is given below. while(1) is there to wait forever for signals.
#include <signal.h>
void main(void)
{
void Traite_Sig (int Number);
int Nb_Sig ;
for (Nb_Sig = 1; Nb_Sig < NSIG ; Nb_Sig ++)
{
***
}
while(1); /* wait for signals */
}
/************* Treatment function **************/
void Traite_Sig (int Number)
{
printf("Hello. Received signal %d !\n", Number);
***
}
DO THE SAME AS ABOVE
Warning:
On System V UNIX systems such as Solaris, you have to "rearm"
the signal treatment by calling signal(sig_num, function)
once a signal has been received once (otherwise the default treatment
is
used).
Write a program that defines a function to execute upon SIGFPE reception.
Program skeleton :
/*********** SIGFPE specific treatment ***************/
#include <stdio.h>
#include <signal.h>
void main(void)
{
***
signal(SIGFPE, Traite_FPE);
***
while (1)
{
***
/* trigger a SIGFPE signal for example by dividing and integer by zero
*/
***
}
}
/*********** SIGFPE signal treatment ********/
void Traite_FPE (int Num)
{
printf("Pid %d receives signal %d\n", getpid(), Num);
***
}
Questions :
Write a program that :
Start the program and send it signals including SIGUSR1 and SIGUSR2, from another window using kill.
Program skeleton:
#include <signal.h>
void main (void)
{
***
/* Put here treatment for all signals (except SIGUSR1,SIGUSR2)
*/
***
/* Put here treatment for SIGUSR1 and SIGUSR2 */
***
while (1); /* wait for signals */
}
/*************** func function **************/
void func (int SignalNum)
{
***
}
/*************** func1
function **************/
void func1 (int SignalNum)
{
***
}
/*************** func2
function **************/
void func2 (int SignalNum)
{
***
}