24 lines
1.0 KiB
Plaintext
24 lines
1.0 KiB
Plaintext
Assignment name: philosophers_bonus
|
|
Expected files: philosophers_bonus.c
|
|
Allowed functions: memset, printf, malloc, free, write, fork, kill, exit,
|
|
pthread_create, pthread_detach, pthread_join, usleep, gettimeofday,
|
|
waitpid, sem_open, sem_close, sem_post, sem_wait, sem_unlink
|
|
-------------------------------------------------------------------------
|
|
|
|
Implement the bonus version of Philosophers:
|
|
- Each philosopher is a separate process (not thread)
|
|
- Use named POSIX semaphores for coordination
|
|
- Parent process monitors all child processes
|
|
- If a philosopher dies, kill all other processes
|
|
|
|
Additional features:
|
|
- Proper cleanup of named semaphores
|
|
- Signal handling (SIGINT, SIGTERM)
|
|
- Final report with statistics
|
|
|
|
Usage: `./philosophers_bonus 5 800 200 200 7`
|
|
|
|
Hint: Bonus part uses processes instead of threads.
|
|
Named POSIX semaphores allow communication between processes.
|
|
Use fork() to create child processes and waitpid() to monitor.
|
|
Semaphore cleanup is crucial - use sem_unlink() and signal handling for cleanup in case of interruption. |