# CSE344 – System Programming – Homework #4 solution

\$24.99

Original Work ?

## Description

5/5 - (1 vote)

Let’s assume for the sake of simplicity that one needs exactly 4 ingredients for preparing a portion of şekerpare: – eggs – flour – butter – sugar
There are N chefs in a street , and each has an endless supply of two distinct ingredients and lacks the remaining two:
e.g. chef1 has an endless supply of eggs and flour but lacks butter and sugar, chef2 has an endless supply of eggs and sugar but lacks flour and butter, chef3 has an endless supply of butter and sugar but lacks eggs and flour, etc.
Every chef sits in front of her/his store and waits for the remaining two ingredients to arrive so that she/he can prepare şekerpare.
There is also a wholesaler that every once in a while delivers two random and distinct ingredients out of the 4 to the street of the chefs and then waits for one of the chefs to prepare the şekerpare. We are assuming there is exactly one chef among the N with the right missing ingredients that can prepare the dessert. Once the dessert is ready, the wholesaler takes it for sale and the chefs wait again for the next round.
Your objective is to implement the chefs and the wholesaler as N+1 processes that print on screen their activities. If your program is successful it could for instance print something like the following:
… chef2 is waiting for flour and butter chef3 is waiting for eggs and flour chef1 is waiting for butter and sugar … wholesaler delivers eggs and flour chef3 has taken the eggs wholesaler is waiting for the dessert chef3 has taken the flour chef3 is preparing the dessert chef3 has delivered the dessert to the wholesaler wholesaler has obtained the dessert and left to sell it chef3 is waiting for eggs and flour …
Rules a) Your program must handle eventual errors gracefully according to the POSIX traditions. b) All N+1 processes must terminate in case CTRL-C is sent to any of the N+1 processes.