open FIFO erro
- From: "freegnu" <freegnu@xxxxxxx>
- Date: Mon, 25 Sep 2006 12:29:03 +0800
hi all , i have a test program, which the prarent process write "hello
world" to a FIFO , and the child process read it form the FIFO,and printf it
on the screem.
but when i run the test program, it open the FIFO,there some problem happen.
the prarent process hand up on open(), and
the child process has error take place
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define FIFO_SERVER "/tmp/fifoserver"
main(int argc,char** argv)
{
int fd;
char w_buf[1024] = "hello world";
char r_buf[1024];
int real_wnum;
memset(w_buf,0,1024);
if((mkfifo(FIFO_SERVER,O_CREAT|O_EXCL)<0)&&(errno!=EEXIST))
printf("cannot create fifoserver\n");
if(fd==-1)
if(errno==ENXIO)
printf("open error; no reading process\n");
if(fork() > 0)
{
if ((fd = open(FIFO_SERVER,O_WRONLY,0)) < 0) // hand up on open()
{
printf("parent open error\n");
if(EEXIST == errno)printf("pEEXIST\n");
if(EACCES == errno)printf("pEACCES\n");
if(EROFS == errno)printf("pEROFS\n");
if(EFAULT == errno)printf("pEFAULT\n");
if(EINVAL == errno)printf("pEINVAL\n");
if(ENAMETOOLONG == errno)printf("pENAMETOOLONG\n");
if(ENOTDIR == errno)printf("pENOTDIR\n");
if(ENOMEM == errno)printf("pENOMEM\n");
if(ELOOP == errno)printf("pELOOP\n");
if(EIO == errno)printf("pEIO\n");
}
real_wnum=write(fd,w_buf,15);
if(real_wnum==-1)
{
if(errno==EAGAIN)
printf("write to fifo error; try later\n");
}else{
printf("real write num is %d\n",real_wnum);
}
}else{
if ((fd = open(FIFO_SERVER,O_RDONLY,0)) < 0)
{
printf("child open error\n");
if(EEXIST == errno)printf("cEEXIST\n");
if(EACCES == errno)printf("cEACCES\n");// the errno happen, it print out
cEACCES
if(EROFS == errno)printf("cEROFS\n");
if(EFAULT == errno)printf("cEFAULT\n");
if(EINVAL == errno)printf("cEINVAL\n");
if(ENAMETOOLONG == errno)printf("cENAMETOOLONG\n");
if(ENOTDIR == errno)printf("cENOTDIR\n");
if(ENOMEM == errno)printf("cENOMEM\n");
if(ELOOP == errno)printf("cELOOP\n");
if(EIO == errno)printf("cEIO\n");
}
read(fd, r_buf, 100);
printf("%s\n", r_buf);
}
}
.
- Follow-Ups:
- Re: open FIFO erro
- From: jasen
- Re: open FIFO erro
- From: kondal
- Re: open FIFO erro
- Prev by Date: Re: scope of linux in the corporates...
- Next by Date: game monitor app
- Previous by thread: mp3 playing library for C++
- Next by thread: Re: open FIFO erro
- Index(es):
Relevant Pages
|