64,692
社区成员
发帖
与我相关
我的任务
分享
//write.cpp
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<fcntl.h>
/*create FIFO*/
int main(void)
{
char buf[80];
int fd;
unlink( "zieckey_fifo" );
mkfifo( "zieckey_fifo", 0777 ); /*create FIFO*/
char s[] = "Hello!\n";
fd = open( "zieckey_fifo", O_WRONLY );
while(1)
{
write( fd, s, sizeof(s) );
sleep(1);
}
return 0;
}
//read.c
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<fcntl.h>
int main(void)
{
int fd;
char buf[80];
fd = open( "zieckey_fifo", O_RDONLY );
while(1)
{
read( fd, buf, sizeof(buf) );
printf("%s\n", buf);
sleep(1);
}
return 0;
}