|
我写了wfifo.c 和 rfifo.c
wfifo.c在后台运行
程序如下:
/*****************wfifo.c********************/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <asm/limits.h>
int main(void)
{
int resdfifo,dummyfd;
int nLen;
char szBuf[1024];
mode_t mode =666;
if((mkfifo("/var/ff",mode)<0)&&(errno!=EEXIST))
{
printf("creat fifo error\n");
}
dummyfd =open("/var/ff",O_WRONLY,0);
nLen=sprintf(szBuf,"wfifo send the message");
if(write(dummyfd,szBuf,nLen+1)<0)
{
printf("open the fifo write error\n");
close(dummyfd);
exit(-1);
}
close(dummyfd);
return 0;
}
/****************rfifo.c******************/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <asm/limits.h>
int main(void)
{
int nFd;
int nLen;
char szBuf[1024];
if((nFd=open("/var/ff",O_RDONLY))<0)
{
printf("open the fifo read error\n");
exit(-1);
}
while((nLen=read(nFd,szBuf,1024))>0)
printf("read fifo: %s\n",szBuf);
close(nFd);
unlink("/var/ff");
return 0;
}
然后编译
/> wfifo &
[16]
/> rfifo
read fifo: wfifo send the message
/> rfifo
open the fifo read error
pid 18: failed 65280
为什么我再读FIFO时,FIFO就空了呢
如何每次读FIFO时,FIFO里都有数据呢
求大虾指点 |
|