void death_handler(int sig)
This article will dissect everything you need to know about 42 Exam 06: what it covers, why it is different from the previous exams, how to prepare, and the strategies to execute on exam day. In the 42 curriculum, there are usually 6 core written exams (Exam 00 through Exam 06), though numbering varies slightly by campus. 42 Exam 06 is the final C exam. Unlike Exam 02 (pointers and memory) or Exam 03 (mini-shells), Exam 06 focuses almost exclusively on Concurrency . 42 Exam 06
if (sig == SIGALRM) printf("%lld %d died\n", get_time(), philos_id); exit(1); Unlike Exam 02 (pointers and memory) or Exam
Remember: You are allowed man . You are allowed to printf debug (but remove it before submission). You are allowed to fail twice before the exam closes. Use your first attempt to scope the exact requirements, then restart. You are allowed to fail twice before the exam closes
sem_t *forks; forks = sem_open("/forks", O_CREAT, 0644, number_of_philosophers); // ... later sem_wait(forks); // eat sem_post(forks); // finally sem_close(forks); sem_unlink("/forks"); The Moulinette resets /dev/shm/ . Use unique names like /sem_philo_<pid> to avoid conflicts. Step 3: Simulate Death with alarm() and sigaction A common pattern in Exam 06 is to set a SIGALRM in each child. If time_to_die passes without resetting the alarm, the child kills itself. This is cleaner than having the parent poll every millisecond.
struct timeval tv; gettimeofday(&tv, NULL); return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000));