A modular multi-process dungeon crawler built on Linux with
fork & exec,
POSIX signals, and
semaphore synchronization
Three forked child processes, each executing their own binary via execl()
Four stages of peril — each requiring a different IPC mechanism to overcome
shm_enemyshm_barriershm_trapReal-time inter-process communication — signals, shared memory ops, and semaphore calls
How the multi-process RPG engine is wired under the hood
game.c is the launcher. It calls fork() three times and uses execl() to replace each child with barbarian, wizard, or rogue binaries. The parent tracks all child PIDs.
POSIX shm_open() + mmap() creates named shared memory segments. Each dungeon stage uses a dedicated struct so processes can read/write game state without pipes.
kill(pid, SIGUSR1) coordinates turn order. The game launcher signals which character should act next. Handlers registered via sigaction() wake sleeping processes.
POSIX named semaphores (sem_open) guard the treasure room door. Two party members call sem_wait() to hold levers open while the Rogue calls sem_post() after collecting treasure.
The parent process loops through dungeon stages, dispatching signals to the appropriate child. Each child reads/writes shared memory, then signals completion back to the parent.
On SIGINT or normal exit, the parent calls shm_unlink(), sem_unlink(), and waitpid() to reap children and free all IPC resources cleanly.