CS631 -- Advanced Programming in the UNIX Environment

Signals Exercise: Play the Signals Game of Thrones

Write a program implementing the following eternal competition for dominance, nicknamed "Signals Game of Thrones" or "SIGGOT":

  • at startup, the program forks
  • each parent and child then:
    • go to sleep for a random amount of time
    • after sleeping, they increment a per-process shots counter and send a random signal number 1 - 32 to the other process
    • if either process receives any signal that it can catch other than SIGINFO or SIGCHLD, it will:
      • increment a per-process defense counter
      • if the signal was SIGABRT, it will then send the KILL signal to the other process
  • once a process has killed the other process, it will then loop around, fork again and repeat the process ad infinitum
  • if either process receives the SIGINFO signal, it will print the current hit/defense counters of the two processes
  • when a process terminates, it will print out its currernt hit/defense counters

How will your program behave with respect to zombie processes? How will you ensure that your program doesn't forkbomb? Will your program ever return? If so, will it leave background processes running?

How can you improve the game to have the process that kills a process take over that process's hits?

[Course Website]