📄 main.c
字号:
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <signal.h>
#include "piped/piped.h"
char buffer[128];
char oldbuffer[128];
static int firsttimeread_flag=0;
static int test=0;
void read_buffer()
{
struct timeval tp;
float micro;
gettimeofday (&tp, NULL);
micro=tp.tv_usec;
printf("%f\n",micro);
if(test%10==0)
{
strcpy(buffer,"hangfei");
}
else
{
strcpy(buffer,"feihang");
}
if(firsttimeread_flag==0)
strcpy(buffer,oldbuffer);
firsttimeread_flag=1;
test++;
if(test==400)
{
test=0;
}
}
int compare_buffer()
{
if((strcmp(buffer,oldbuffer))!=0)
{
printf("buffer change!\n");
strcpy(oldbuffer,buffer);
return 1;
}
return 0;
}
void microsecond_sleep(long ms)
{
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = ms;
//http://linux.chinaitlab.com/administer/734331.html
select(FD_SETSIZE,NULL,NULL,NULL,&timeout);
}
int init()
{
if(!pipedInit())
{
printf("piped_Init_error\n");
return 0;
}
return 1;
}
int main(void)
{
if(!init())
{
printf("inital error!\n");
return 0;
}
signal(SIGCHLD,SIG_IGN);
while (1)
{
microsecond_sleep(2000000);
read_buffer();
if(compare_buffer()==1)
{
write_pipe(buffer);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -