Question: Using sockets, you will write a program that uses fork( ) to create two child processes that will play rounds of RPS. The child processes

Using sockets, you will write a program that uses fork( ) to create two child processes that will play rounds of RPS. The child processes will wait until the parent signals that they should choose their next throw. The children should repeat this wait-throw-wait process until they are signaled to exit.

The parent process should output each childs process id and, for each round, output each childs throw and the result of the round. After the tournament is over, the parent should output the aggregate results. For example:

 Using sockets, you will write a program that uses fork( )

$./rps1 3 Child 1 PID: 113 Child 2 PID: 114 Beginning 3 Rounds. Fight! Round 1: Child 1 throws Scissors! Child 2 throws Rock! Child 2 Wins! Round 2: Child 1 throws Paper! Child 2 throws Scissors! Child 2 Wins! Round 3: Child 1 throws Paper! Child 2 throws Rock! Child 1 Wins! Results: Child 1:1 Child 2: 2 Child 2 Wins! $./rps1 3 Child 1 PID: 113 Child 2 PID: 114 Beginning 3 Rounds. Fight! Round 1: Child 1 throws Scissors! Child 2 throws Rock! Child 2 Wins! Round 2: Child 1 throws Paper! Child 2 throws Scissors! Child 2 Wins! Round 3: Child 1 throws Paper! Child 2 throws Rock! Child 1 Wins! Results: Child 1:1 Child 2: 2 Child 2 Wins

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!