Question: Moving on to the next; } printf(Child %d won! ,currentChild); // II.E. Clean up after game: // II.E.1. Tell all processes to end themselves: for
Moving on to the next; } printf("Child %d won! ",currentChild); // II.E. Clean up after game: // II.E.1. Tell all processes to end themselves: for (currentChild = 0; currentChild // YOUR CODE HERE TO SEND 'SIGINT' TO 'childPidArray[currentChild]' sleep(1); } // YOUR CODE HERE TO SEND 'SIGINT' TO 'pinataPid' sleep(1); // II.E.2. Clean up memory: free(childPidArray); // III. Finished: return(EXIT_SUCCESS); }
Communication protocol example:
gameOfficial | | pinata +--(fork/execl)------------------------>>+ (gameOfficial makes the pinata) | | | child1 | +--(fork/execl)---------->>+ | (gameOfficial makes child1) | | | | child2 | | +--(fork/execl)>>+ | | (gameOfficial makes child2) | | | | | | | | | | | | | | | | | | | | | | | | | | | | +--(SIGUSR1)-----|------->>+ | Control to Child1: "Your turn" | | | | | | +-(SIGUSR1)->>+ Child1 to Pinata: "Whack!" | | | | | | +->+ | | Control to Child2: "Your turn" | | | | | +---------|-(SIGUSR1)->>+ Child2 to Pinata: "Whack!" | | | | | +---------|->+ | Control to Child1: "Your turn" | | | | | | +-(SIGUSR1)->>+ Child1 to Pinata: "Whack!" | | | | | | +->+ | | Control to Child2: "Your turn" | | | | | +---------|-(SIGUSR1)->>+ Child2 to Pinata: "Whack!" | | | | | +---------|->+ Control to Pinata "Time to stop" | | | | | | | (process ends) | | | +--(SIGINT)------|------->>+ Control to Child1 "Time to stop" | | | | | (process ends) | | +--(SIGINT)---->>+ Control to Child2 "Time to stop" | | | (process ends) |


![TO 'childPidArray[currentChild]' sleep(1); } // YOUR CODE HERE TO SEND 'SIGINT' TO](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3ad1c84a92_59666f3ad1c0711d.jpg)
The gameOfficial's job is to ask for the number of children, launch the pinata process, launch the desired number of children, and then regulate the game. After one of the children has reported that it has won then it should send SIGINT to the pinata and all children processes. It should also reap them with waitpido. Your gameofficial program must: B Insall a stcouLD signal handler This handler shoald have a whi oop hat dos a non-hanging waitpido)that etets wheher or not a hild process including pinata process) has ended. If it has it should print that process's PID and whether or not it ended successfully or crashed. C. Install sIGUSR1 signal handler turnover(). This function tells the gameOfficial that the current child has finished its turn, but that the game has not yet finished D. Install stousa2 signal handler turnverstopsame). This function tells the gameOfficial both that the current child has finished its turn and that the game has finished E. Have a loop that regulates which child's turn it is. The loop sends SIGUSR1 to the current child F. After the above loop, have code that sends sIGINT to all child processes (including the pinata process) I have writen much of the gameOfficial program for you. All you have to do is fill in the jwicy bits gameOfficial ganeOfficial.c This program controls version 2.0 of the pinata-whacking .simulator Version 2. 2017 September 27 seph Phillips Common include sequence include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
