#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
#include <stdlib.h>
#define BUFSIZE 500*1024*1024
char buf[BUFSIZE];
static void sig_alrm(int signo) {
    printf("%d\n",time(NULL));
    printf("caught SIGALRM\n");
    fprintf(stderr, "in sig_alrm\n");
}
int main()
{
    int fd;
    fd=open("a.txt",O_WRONLY);
    signal(SIGALRM,sig_alrm);
    printf("%d\n",time(NULL));
    alarm(1);
    write(fd,buf,BUFSIZE);
}
output:
1414899972
1414899976
caught SIGALRM
in sig_alrm
It seems that the SIGALRM was caught about 3 seconds after the call to alarm(1). Why isn't the signal caught right away and the system call restarted?
 
     
    