View Full Version : Piping between processes, using pipes, using low level read() and write()
Inquirer
09-20-2003, 08:06 PM
Okay.. Here is the deal
I have multiple processes. I have a unistd.h pipe open, and one end is a file descriptor (int fd1) and the other is stored in another int (int fd2). Unfortunately, these are ints, so i can't use fread, fwrite, etc, or fputs, fputc. I have been looking around for read and write, but haven't found anything about their usage, just comments that something is a wrapper for it or something. Does anyone know how to use these, or if there is a readline that will do more than one character? same for writeline, if there is one. Also, what is the prototype and return value of it. If there is a website that will help explain these to me, that works just as well. Thanks a ton!
~Eko
chrismiceli
09-20-2003, 08:22 PM
are you talking about unbuffered i/o?
try this
write(fd1, buf, sizeof buf);
memset(&buf, 0, sizeof buf); /* so we know it wasn't just left over */
read(fd2, buf, sizeof buf);
puts(buf);
Inquirer
09-20-2003, 09:01 PM
yeah, unbeffered io... that means nothing to me. I i have tried (the equivalent of) what you showed me, but it still doesn't work. I'm trying varius means of debugging it, to make sure its looking in the right file descriptors, etc, but could you explain what unbuffered io is? does that mean that it has to be waiting to read while it sends for it to be read? or what? I'm too used to C++ streams =/
~Eko
chrismiceli
09-21-2003, 12:20 PM
unbuffered i/o means it sends one at a time, the kernel does not buffer it in some sort of buffer. If you were to write a message, say "message", the kernel would send 'm', wait until it is finished with that, then send 'e' and so on. buffered i/o, the kernel buffers it, so if you sent the same "message", they kernel would probably cache all of it then send the whole thing to be read. Can you show us some code?
Dave_Sinkula
09-21-2003, 03:00 PM
Originally posted by Inquirer
I have a unistd.h pipe open, and one end is a file descriptor (int fd1) and the other is stored in another int (int fd2). Unfortunately, these are ints, so i can't use fread, fwrite, etc, or fputs, fputc. I have been looking around for read and write, but haven't found anything about their usage, just comments that something is a wrapper for it or something. Does anyone know how to use these, or if there is a readline that will do more than one character? same for writeline, if there is one. Also, what is the prototype and return value of it. If there is a website that will help explain these to me, that works just as well. Thanks a ton!read (http://www.rt.com/man/read.2.html)
write (http://www.rt.com/man/write.2.html)
Could fdopen (http://www.rt.com/man/fdopen.3.html) make life easier?
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.