Problems with FIFO pipe using a child and parent process
Hi,
I am trying to write a simple program where my parent writes a small message like "hello" to the child. So the parent writes and the child reads. When I run, I get 'child read from fifo failed: resource temporarily unavailable.' Can someone look at my code and tell me whats wrong or missing? I cant seem to figure it out. It seems like what is happening is that the parent isnt opening the FIFO to write into it, but why?? Thanks so much!! Code:
/* Named pipe pipe1.c */ |
Off the top of my head ... don't you WANT the child to block until there's something to read?
|
You should write to pipe before waiting for client exit. Like this:
Code:
if (write(fd, buf, strsize) != strsize) MT. |
Nonsense. You don't need a "wait()", nor do you need a busy loop if you've forked() the child and you're using a "mkfifo()" queue.
You SHOULD eliminate the "O_NONBLOCK" in your child: Code:
if ((fd = open(argv[1], O_RDONLY)) == -1) Quote:
|
Got to work, dont know what I changed but here is the updated code
I think the O_NONBLOCK was screwing things up..I still dont understand what that does...but when I took it out, it did what it was supposed to do...I took out the wait(&status) function as well...why did that fix my problem..anyone know?
Here is the final code: Code:
nclude <stdio.h> |
Quote:
Quote:
Quote:
|
All times are GMT -5. The time now is 04:36 PM. |