Question: Develop a program that fork() a child process. Let the parent process run Program Example 4.4 in Lecture 4 using execl(). Let the child process
Develop a program that fork() a child process. Let the parent process run Program Example 4.4 in Lecture 4 using execl(). Let the child process use system call int kill(pid_t pid, int sig) to deliver signal SIGINT and signal SIGHQUIT to the parent process. Let the child process sleep 3 seconds between delivering signal SIGINT and signal SIGHQUIT.
Program Example 4.4 is as follows:
/*
Catching a signal
*/
#include
#include
#include
#include
int main() {
int i;
void signal_catcher(int);
if (signal(SIGINT, signal_catcher) ==SIG_ERR)
{
perror(SIGINT);
exit(1);
}
if (signal(SIGQUIT, signal_catcher) ==SIG_ERR) {
perror(SIGQUIT);
exit(2);
}
for (i=0; ; ++i) {
printf(%i , i);
sleep(1);
}
}
void signal_catcher(int the_sig) {
signal(the_sig, signal_catcher); /*reset*/
printf( Signal %d received. , the_sig);
if (the_sig == SIGQUIT)
exit(3);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
