64,637
社区成员
发帖
与我相关
我的任务
分享
#include<unistd.h>
#include<signal.h>
#include<stdio.h>
#include<string>
#include <iostream>
using namespace std;
void handler(int)
{
char szBuf[100];
time_t timer = time(NULL);
strftime(szBuf, sizeof(szBuf), "%Y-%m-%d %H:%M:%S", localtime(&timer));
printf("%s/n", szBuf);
}
int main()
{
signal(SIGALRM, handler); //让内核做好准备,一旦接受到SIGALARM信号,就执行 handler
while(1)
{
alarm(1800);
}
return 0;
}
刚看的这些内容,不知道改得对不对,你试试吧。