I want to simulate a game server that should continuously send and receive signals with its parent. The scenario is as follows:
static int game_s;
game_s = fork();
By default the reception of a specific signal is blocked from the moment a process received this specific signal until the related signal handler had been left.
man 3 signal:
void (*signal(int sig, void (*func)(int)))(int);
When a signal occurs, and func points to a function, it is implementation-defined whether the equivalent of a:
is executed or the implementation prevents some implementation-defined set of signals (at least including sig) from occurring until the current signal handling has completed.
To change this behaviour establish the signal handling via
sigaction() instead of
signal() (which one should do any ways for portability reasons).
sigaction() takes a
struct sigaction. The member
sa_flags of the latter should have
man 2 sigaction:
Do not prevent the signal from being received from within its own signal handler. This flag is meaningful only when establishing a signal handler.
If set and sig is caught, sig shall not be added to the thread's signal mask on entry to the signal handler unless it is included in sa_mask. Otherwise, sig shall always be added to the thread's signal mask on entry to the signal handler.
Be aware that each signal handler gets it's own stack allocated each time it gets invoked, so sooner or later this recursive ping-pong ends up in an out-of-memory condition.