Thread: Piping between processes, using pipes, using low level read() and write()

  1. #1

    Piping between processes, using pipes, using low level read() and write()

    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
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  2. #2
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    are you talking about unbuffered i/o?
    try this
    Code:
    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);
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  3. #3
    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
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  4. #4
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    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?
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005

    Re: Piping between processes, using pipes, using low level read() and write()

    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
    write


    Could fdopen make life easier?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-06-2009, 12:27 PM
  2. Problems with fstream, one variabile for write and read
    By Smjert in forum C++ Programming
    Replies: 3
    Last Post: 02-03-2009, 10:19 PM
  3. read write lock in C#
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 04-16-2008, 08:49 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM