Posted on 1998-05-03
We have to write a Sleeping Barber program that implements two functions, Barber() and Customer(). The main program will have to create several children using the fork system call. Five of the children should be customers and two should be barbers. Barbers should be numbered one and two, and customers one through five. We should use the POSIX V system calls semget, semctl, and semop.
Each time a new barber is created, it calls the Barber() function and stays there until the program exits. Similarly, each time a new customer is created, it calls the Customer() function and stays there until the program exits. In order to show how the customer and barber processes communicate, make them print their interaction in the following form
Barber 1 is servicing:
Barber 2 is servicing:
Instead of calling cut_hair() and get_haircut(), make the processes sleep for 2 seconds (use the sleep system call). The parent process in your program should sleep for 15 seconds allowing for the barber customer interaction should happen. Then it should send all children termination signal and exit.