/* Compile this as follows: * gcc -O0 -o raise raise.c * The C standard on signal() guarantees that the execution of raise will * terminate. * * Compile this as follows: * gcc -Os -o raise raise.c * The C standard on signal() guarantees that the execution of raise will * terminate. * * Compile this as follows: * gcc -O2 -o raise raise.c * The C standard on signal() guarantees that the execution of raise will * terminate. */ #include #include #include int terminated; static void handler(int signo) { terminated = 1; } int main(int argc, char **argv) { unsigned total = 0, delta = drand48() >= argc ? 1 : 0; /* At runtime, delta will be 0 as argc is one */ signal(SIGUSR1, handler); /* This is an infinite loop unless terminated is 1 as delta is surely 0 */ for (int i = 0; !terminated && i < 100; i += delta) { total += i; raise(SIGUSR1); } return total; }