What about:
alarm(5);
alarm(0);
Alternatively you can use setitimer.
As R. Martigno Fernandez said:
The function alarmorders the current process to receive SIGALRM 5 seconds after it is called. The default action for SIGALRMsi to abort the process is abnormal. A call alarm(0)disables the timer.