This is a simple way to make a code be executed from time to time, using alarm().
#include
#include
#include
static void
run(int signal)
{
printf("signal = %i\n", signal);
alarm(1);
}
int main(int argc, char **argv)
{
struct sigaction act;
act.sa_handler = run;
if(sigaction(SIGALRM, &act, NULL))
{
fprintf(stderr, "Error adding handler for SIGALRM.\n");
return 1;
}
alarm(1);
while(1);
return 0;
}