Question: 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

Complete the attached template program with the following process synchronization behavior. This synchronization process continues forever.

Complete the attached template program with the following process synchronization behavior. This

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

#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);

}

Parent Process (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 Databases Questions!