I'm trying to execute this code:
If you just put
alarm(1) in the loop in your example, you'll call
alarm(1) infinitely many times within a few microseconds of each invocation. And then this happens:
If an alarm has already been set with alarm() but has not been delivered, another call to alarm() will supersede the prior call.
I.e., the alarm gets cleared in each iteration of the loop. And since your loop runs forever, the alarm is never permanently set.