|
发表于 2004-10-15 16:54:46
|
显示全部楼层
[code:1]
#include <stdio.h>
#include <sys/time.h>
#include <signal.h>
#include <unistd.h>
#define DELAY_SEC 1
#define DELAY_USEC 0
volatile int count = 0;
char buf[16];
void sig_action()
{
memset (buf, 0, 16);
sprintf(buf, "%d\n", count++);
write(1, buf, 16);
fsync(1);
}
int main()
{
struct sigaction act, oldact;
struct itimerval value, ovalue;
int i;
/* signal route */
act.sa_handler = sig_action;
act.sa_flags = 0;
sigaction(SIGALRM, &act, &oldact);
value.it_value.tv_usec = DELAY_USEC;
value.it_value.tv_sec = DELAY_SEC;
value.it_interval.tv_usec = DELAY_USEC;
value.it_interval.tv_sec = DELAY_SEC;
printf("%d, %d\n", DELAY_SEC, DELAY_USEC);
setitimer(ITIMER_REAL, &value, &ovalue);
for (i = 0; i < 10; i++) {
sleep(10);
}
sigaction(SIGALRM, &oldact, NULL);
return 0;
}
[/code:1] |
|