-1
Ben UNIX boruları ve sinyalleri hayranlarıyla sorun kullanılarak şu soru çözmek için nasıl karıştı aşağıdaki- olarakUNIX boruları ve sinyalleri kullanarak aşağıdaki Uygulamak
There are N players (numbered 0 to N-1) that sit in a circle and play the following game. The first person
(player 0) starts with a token of initial value Tok_value. If the value of the token is not 0 it decrements the
value of token by one and passes it to the next person (player 1). The receiver (player 1) checks if the
token is 0 or not, if not the receiver just decrements the value of the token by one and passes it to the next
person (player 2) and so-on. Otherwise, if the value of token was zero the receiver collects a point and
passes a new token with initial value of Tok_value to the next player. The first player to collect Pt points
wins and then kills all the others.
For example: If N = 9, Tok_value = 4 and Pt = 2, the players are numbered 0 to 8. Player 4 gets the first
point then player 0 gains a point and so on. In this example players gain points in the following order 4, 0,
5, 1, 6, 2, 7, 3, 8, 4 and 4 wins because it is the first one to get Pt=2 points.
Write a program to simulate the above game. You program should get the inputs N, Tok_value and Pt from
the user. It then spawns N processes and then links the last process to the first. The linking is being done
through unnamed pipes (i.e. there should be a pipe between two consecutive persons). The i th process
represents the i th person in the circle. Note that the first process has to generate two pipes, one to
communicate with the second process and one with the last process. The token is passed using UNIX
unnamed pipes. The winner kills the losers by sending the signal SIGTERM along the circle. (Refer to
kill() system call for this). Before each loser is killed, he has to close the pipes which he uses (i.e., you
have to write a signal handler for SIGTERM).
You must output the progress of the game. E.g. when a receiver gets a token it prints something like the
following: -
I am player number <X>. I have received a token with value <Y> and I am now sending token to player
<Z>. My current points are <W>.
If a player wins it prints:
I am player number <X>. I have <Y> points. I have won!!!
Each player that is killed prints before exiting:
I am player number <X>. I have been killed.
herkes bu ilgili çözümleri veya ipuçları paylaşabilir misiniz . Kod çözümü takdir edilecektir.