Question
#include int ntimes = 0; main() { pid_t pid, ppid; void p_action(int), c_action(int); static struct sigaction pact, cact; pact.sa_handler = (a) _______; sigaction((b) _______, &pact,
#include
int ntimes = 0;
main()
{
pid_t pid, ppid;
void p_action(int), c_action(int);
static struct sigaction pact, cact;
pact.sa_handler = (a) _______;
sigaction((b) _______, &pact, NULL);
switch(pid = fork()) {
case -1: /* error */
perror("synchro");
exit(l);
case 0: /* child */
/* set action for child */
cact.sa_handler = (c)_______;
sigaction((d)______, &cact, NULL);
/* get parent process-id */
ppid = getppid();
for (;;)
{
(e)________ ;
sleep(1);
(f)________;
}
/* never exits */
default: /*parent */
for(;;)
{
sleep(1);
(g)__________;
(h)_________;
}
/* never exits */
}
}
void p_action(int sig)
{
printf("Parent caught signal #%d ", ++ntimes);
}
void c_action(int sig)
(
printf("Child caught signal #%d ", ++ntimes);
}
do this entire problem with working code and you will get your thumbs up. just give me the fill in of a-h Complete the attached template program with the following process synchronization behavior. This synchronization process continues forever. Note that SIGUSR2 is used from Parent to Child process, and SIGUSR1 is used from Child to Parent process. The order of signal generations are noted as numbers in the above diagram, (1) and (2). The output from your program should be: Child caught signal\# 1 Parent caught signal\# 1 Child caught signal\# 2 Parent caught signal\# 2 Child caught signal\# 3 Parent caught signal\# 3 Enter the missing fields, (a) through (h), into the Blackboard "Final Exam Submission." You may refer to the example program "synchro.c" in page 144-145 in the textbook, which is implementing a slightly different synchronization behavior. /* synchro */ \#include h>
#include
int ntimes = 0;
main()
{
pid_t pid, ppid;
void p_action(int), c_action(int);
static struct sigaction pact, cact;
pact.sa_handler = (a) _______;
sigaction((b) _______, &pact, NULL);
switch(pid = fork()) {
case -1: /* error */
perror("synchro");
exit(l);
case 0: /* child */
/* set action for child */
cact.sa_handler = (c)_______;
sigaction((d)______, &cact, NULL);
/* get parent process-id */
ppid = getppid();
for (;;)
{
(e)________ ;
sleep(1);
(f)________;
}
/* never exits */
default: /*parent */
for(;;)
{
sleep(1);
(g)__________;
(h)_________;
}
/* never exits */
}
}
void p_action(int sig)
{
printf("Parent caught signal #%d ", ++ntimes);
}
void c_action(int sig)
(
printf("Child caught signal #%d ", ++ntimes);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started