#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#define MAXBUFSIZE 1024
static int g_flag = 0;
void sigalrm_fn(int sig)
{
g_flag = 1;
alarm(1);
return;
}
int main(void)
{
FILE* file = NULL;
char *buf = NULL;
time_t ts = 0;
buf = calloc(1, 30);
file = fopen("/home/nec/hejian/Command.log", "w+");
if(file == NULL) {
printf("file open faile!\n");
}
signal(SIGALRM, sigalrm_fn);
alarm(1);
while(1) {
ts = time(NULL);
memset(buf, 0, 20);
sprintf(buf, "lps time = %lu\n", ts);
if (g_flag == 1) {
g_flag = 0;
fwrite(buf, strlen(buf), 1, file);
fflush(file);
}
}
free(buf);
fclose(file);
return 0;
}
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#define MAXBUFSIZE 1024
static int g_flag = 0;
void sigalrm_fn(int sig)
{
g_flag = 1;
alarm(1);
return;
}
int main(void)
{
FILE* file = NULL;
char *buf = NULL;
time_t ts = 0;
buf = calloc(1, 30);
file = fopen("/home/nec/hejian/Command.log", "w+");
if(file == NULL) {
printf("file open faile!\n");
}
signal(SIGALRM, sigalrm_fn);
alarm(1);
while(1) {
ts = time(NULL);
memset(buf, 0, 20);
sprintf(buf, "lps time = %lu\n", ts);
if (g_flag == 1) {
g_flag = 0;
fwrite(buf, strlen(buf), 1, file);
fflush(file);
}
}
free(buf);
fclose(file);
return 0;
}