Fifo task

A smart process chooser

The task is to write a pair of programs: a client and a server. As a result of their operation "a best" client process should be selected.
After the server has been run, it is waiting for exactly three clients to connect to its fifo. Each of the connected clients sends
a single message over the fifo (atomically). The message contains the pid of the connected client and a random integer number.
The server shall now collect all three messages and choose some random client in the following way:
add all three random numbers modulo 3 - the result is assumed to be the index of the connected client which is a winner.
The pid of the winner should be written by the server to a regular file winner.txt. SIGPIPE signals should be ignored.

Example:
client 0 sends: [3000, 1234]
client 1 sends: [3001, 2345]
client 2 sends: [3002, 3456]
server calculates:
(1234 + 2345 + 3456) % 3 = 7035 % 3 = 0
the winner is client: 0
server writes a number 3000 to an output file

Hint:
mkfifo(), close(), read(), write(), getpid(), srand()/rand(), itoa()

Upload solutions to:
/home2/samba/dobrowolskip/unix