Question: so this is my current code how do i implement this to the code : Before calling sigaction ( ) , you should first use

so this is my current code how do i implement this to the code : Before calling sigaction(), you should first use sigemptyset() to empty the signal set. (Use '$ man
sigemptyset' to find out the details.). Modify your test_signal.cpp program above by using sigaction () to
intercept SIGINT; replace the "for" loop with "while (1); you should be able to quit the program by
entering "^\".(Need to intercept SIGQUIT.). here is my code : //test_alarm.cpp
#include
#include
#include
using namespace std;
//simulates an alarm clock
void alarm_off(int sig)
{
cout << "Alarm has gone off "<< endl;
}
//tell child process to wait for 5 seconds before sending
//a SIGALRM signal to its parent.
int main()
{
int pid;
cout << "Alarm testing!" << endl;
if ((pid = fork())==0){//child
sleep (5);
/*
Get parent process id, send SIGALARM signal to it.
*/
kill (getppid(), SIGALRM);
return 1;
}
//parent process arranges to catch SIGALRM with a call
//to signal and then waits for the inevitable.
cout << "Waiting for alarm to go off!" << endl;
(void) signal (SIGALRM, alarm_off);
pause(); //process suspended, waiting for signals to wake up
cout << "Done!" << endl;
return 1;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!