A: Try sys/select.h.
A:
read() will return a 0 when the writing end of a FIFO has
exited or closed the FIFO (and there is no data left).
If you write to a pipe the is no longer open for reading by any
process, you will get a SIGPIPE which by default will terminate
your program.
A: You can do whatever you want (neither is required), but it
makes sense to exit when the other end of the connection has closed
the FIFO (possibly by exiting) and to clean up FIFOs before
exiting.
A:
a named pipe opened for reading will block on the open() until somebody
opens it for writing, and one opened for writing will block until
it's opened for reading.
A:
As we discussed in class, a line at a time is fine.
A:
fflush(). I think you just need stdio.h but you might want to check
the man page.
(The setvbuf() command turns off buffering so you don't need to flush
anything.)
open("/tmp/write.4\201\3\1\13", 0, .....instead of just "/tmp/write.4" like it should be. Do you have any ideas what could be causing this? The other fifo, whose name is read in first, opened fine.
A:
It looks like you're writing the name into the pipe with something
like
write(fd, pipename, strlen(pipename))instead of
write(fd, pipename, strlen(pipename)+1)Note that strlen doesn't count the terminating \0 character, which you need to send.
A: sprintf().
... char buffer[25]; int n = 123; sprintf(buffer, "%d", n); ...
A:
The problem is that you are treating what you read from a fifo as
null-terminated strings, although you are not sending the null. You
could just use write to send output to the screen - write does not
care about null termination, it just needs to known how many
characters it should send to stdout. You could also just send the null
over with each string:
You are probably doing something like this:
write(thefifo,string,strlen(string));which does not send the null. The following does send the null
write(thefifo,string,strlen(string)+1);