Do not use busy-waiting (while loops checking time). The Moulinette will penalize you for CPU overuse. Use usleep() to yield the CPU, but be careful— usleep() is inaccurate for long simulations. Use select() or nanosleep() for precision.
A: No. The exam’s automated grader will flag any artificial delays as inefficient. You must use sigprocmask and proper synchronization.
Here’s a reconstructed problem from a 2023 42 Exam 06 session: 42 Exam 06
Subject: Write a program
signal_pingthat takes no arguments. It creates a pipe, then forks twice (Child A and Child B). Child A sendsSIGUSR1to Child B every second. Child B counts how many signals it receives and prints the count every 5 seconds. The parent must terminate both children cleanly when it receivesSIGTERM.
The hidden challenges:
Why cadets fail: They try to use a global variable across processes (impossible without shared memory). They forget that fork copies memory, not shares it.
The correct approach: Use the pipe as a control channel. Parent writes "EXIT" to the pipe, children read from it. Do not use busy-waiting (while loops checking time)
Precision is mandatory. You will calculate timestamps in milliseconds to check if current_time - last_meal_time > time_to_die.