2

I have this code:

mkfifo ("bPipe", 0660); /* Create named pipe */ int fd1 = open ("bPipe", O_WRONLY|O_NONBLOCK); /* Open named pipe for writing */ perror("FD1"); int fd = open ("bPipe", O_RDONLY|O_NONBLOCK); /* Open it for reading */ perror("FD"); char*mex="Hello world\n\0"; write (fd1,mex , getStringLenght(mex)+1); char* result = readline(fd1); printf("Rc %s : \n",result); 

I'm studying the FIFO in C and I tried to create two FIFO but after opening them I get this two errors:

FD1:Device not configured FD:Device not configured 

and I dont understand why.

P.S "readLine" and "getStringLenght" are my functions

2
  • please share more code - what's is "bPipe"? something like this one ? mknod(FIFO_FILE, S_IFIFO|0666, 0); Commented Jun 29, 2015 at 11:03
  • "bPipe" is fifo's name Commented Jun 29, 2015 at 11:16

2 Answers 2

6

Documentation of fifo(7) states:

A process can open a FIFO in nonblocking mode. In this case, opening for read-only will succeed even if no-one has opened on the write side yet, opening for write-only will fail with ENXIO (no such device or address) unless the other end has already been opened.

That's exactly what you do. You open the pipe for write first but there's not a read end opened yet. If you swap the read/write calls to open() you should be fine.

I believe you are actually checking the return codes of open() before calling perror(). In all cases, you should set errno to 0 before calling a library function (include <errno.h>) as errno might be set to some other value by the some other library/system call.

Sign up to request clarification or add additional context in comments.

3 Comments

sorry I get a strange thing: I opened the first read and then write and now it works, but if I open first write and then read it isn't work. Why?
@mariorazzu Why are you using O_NONBLOCK?
why its the same process and if I dont set O_NONBLOCK flag the program block on open function
1

Looking at your code I really don't see anything, that tells me there's an error here somewhere. As for the printed messages you get, you see, first you have to figure if an error is really there. For that you have to check return values of open(). And only if return values indicate error, then perror() makes sense.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.