The project is to create either a C++ class or wrapper to handle the management of semaphores and shared memory. I chose to create a set of wrapper functions to implement semaphores and shared memory.
I used total number of philosophers + 1 in the project. One semaphore (mutex) is used to control the process entering and exiting the critical sections. Other total number of semaphores is used for children philosophers. These corresponding semaphores are used to block each philosopher for next available time to eat.
The main program is checking input arguments first. If they are correctly inputted, the main will create shared memory and semaphores for each philosopher. And the main will fork off all philosopher processes and will become the waiter.
Philosophers will loop until the philosopher has eaten the time that entered as input. Philosopher will think, hunger, and then eat. The process will acquire two forks or block before it eats. After eaten, put both forks back on table and will die.
The parent will become a waiter after it forked children philosophers. The waiter will report all status of philosophers until all processes are done. Then the waiter will clean up all shared memory and semaphores and will finish the program.