#include #include #include #include #include void handler(int sig) { alarm(1); return; } int main(void) { int i; time_t now; struct tm *pnow; struct sigaction act = { .sa_handler = handler, .sa_flags = SA_RESTART, }; sigemptyset(&act.sa_mask); if (sigaction(SIGALRM, &act, NULL) < 0) return 1; alarm(1); for(i=0;i<60;i++) { sleep(10); now = time(NULL); pnow = localtime(&now); printf("%d:%d:%d\n",pnow->tm_hour,pnow->tm_min,pnow->tm_sec); } exit(0); }