UNIX programming is very easy to encounter this function, we can first look at the introduction of this function, with the man tool, man alarm.
The introduction to the alarm function in online Help for UNIX systems is as follows:
#include <unistd.h>
unsigned int alarm (unsigned int seconds);
Its main function is to set the signal transmission alarm clock. Its main function is to set the signal SIGALRM to the current process after the number of seconds specified by seconds, if the alarm function is called again within the time that is not completed, the latter timer setting overrides the previous setting, and when seconds is set to 0 o'clock, the timer will be canceled. It returns the time remaining for the last timer, and returns 0 if it is set for the first time.
For a simple example:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void Sig_alarm ()
{
exit (0);
}
int main (int argc, char *argv[])
{
signal (SIGALRM, sig_alarm);
Alarm (ten);
Sleep (in);
printf ("Hello world!\n");
return 0;
}
The program ends at 10s and does not output Hello world!