Question: We are creating a C program with the following process synchronization behavior. This synchronization process continues forever. Please choose the proper statements for the lines

We are creating a C program with the following process synchronization behavior. This synchronization process continues forever. Please choose the proper statements for the lines (1) through (8). Each statement should be one of the following statements: (40 points)
(a)pause()
(b)kill (ppid, SIGUSR1)
(c)kill (cpid, SIGUSR1)
(d)kill (gcpid, SIGUSR1)
(e)kill (pid, SIGUSR1)
(f)alarm(0)
(g)alarm(1)
(h)raise(SIGUSR1)
Parent Process
(1) SIGUSR1(4) SIGUSR1
Child
(2) SIGUSR1
(3) SIGUSR1
Grand Child
/* synchro -- example for kill */
#include #include #include #include
int ntimes =0; int ntimes1=0; int ntimes2=0;
int main(){
pid_t ppid, cpid, gcpid, pid;
void p_action(int), c_action(int), gc_action(int); static struct sigaction pact, cact, gcact;
pact.sa_handler = p_action; sigaction(SIGUSR1, &pact, NULL);
switch(cpid = fork()){ case -1: /* error */
signal! */
perror("synchro"); exit(1);
case 0: /* grandchild */ gcact.sa_handler = gc_action;
sigaction(SIGUSR1, &gcact, NULL); cpid = getppid(); /* infinite for loop for exchanging
for(;;){
}
perror("synchro"); exit(1);
case 0: /* child */
switch(gcpid = fork()){ case -1: /* error */
}
sleep(1); ___(1)______; ___(2)______;
default : // child cact.sa_handler = c_action;
sigaction(SIGUSR1, &cact, NULL); ppid = getppid(); /* infinite for loop for exchanging signal! */
for(;;){
sleep(1);
}
/* parent!! */
//// infinite for loop for exchanging signal!
//// for(;;){
}}
___(7)______; sleep(1); ___(8)______;
}
void p_action(int sig)
{
printf("Parent caught signal with ntimes = #%d
",++ntimes); }
void c_action(int sig)
{
printf("Child caught signal with ntimes1= #%d
",++ntimes1); }
void gc_action(int sig)
{
printf("Grand Child caught signal with ntimes2= #%d
",++ntimes2); }
We are creating a C program with the following

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!