Question: Language: C/C++ required WITH comments Using POSIX message queues (mq_overview), play hot potato between six processes (you can use fork()). The original process sends out
Language: C/C++ required WITH comments
Using POSIX message queues (mq_overview), play "hot potato" between six processes (you can use fork()). The original process sends out a message once it has generated five child processes. Each process, excluding the original, attempts to grab the message before again posts it on the message queue. Count the number of messages received by each process and declare the first process to receive one thousand (1,000) messages as the loser. That process is no longer allowed to send and receive messages. Continue with the remaining processes until only one process remains in the game. That final process is the winner. Report the number of messages received by each process during each round.
Use getpid() to ensure that each process has a unique identifier for its output.
Suggestion/Approach:

Please read thoroughly. I will review and vote instantly
Parent program initialization The count variable needs to be volatile Create anonymous pipe to receive messages from children Create message queue for potato passing (include login id as part of the message queue name) Create children Parent processing Parent processing Signal handler Child processing Establish SIGUSR1 handler Top of loop: release potato Send (id, count) to parent on pipe Wait for message on pipe Top of loop: wait for potato Reset count to zero Store loser info Increment counter Return If (count is one thousand) Send SIGUSR1 to all remaining children Send loss message (id, count) to parent Receive messages (id, count) on pipe from all remaining children Wait for SIGUSR1 to terminate (count will be reset to zero) Break if winner is decided Go to top of loop Go to top of loop Share stats with user Wait for children to terminate Unlink the message queue Parent program initialization The count variable needs to be volatile Create anonymous pipe to receive messages from children Create message queue for potato passing (include login id as part of the message queue name) Create children Parent processing Parent processing Signal handler Child processing Establish SIGUSR1 handler Top of loop: release potato Send (id, count) to parent on pipe Wait for message on pipe Top of loop: wait for potato Reset count to zero Store loser info Increment counter Return If (count is one thousand) Send SIGUSR1 to all remaining children Send loss message (id, count) to parent Receive messages (id, count) on pipe from all remaining children Wait for SIGUSR1 to terminate (count will be reset to zero) Break if winner is decided Go to top of loop Go to top of loop Share stats with user Wait for children to terminate Unlink the message queue
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
