mknod FIFO

This is a discussion on mknod FIFO within the Linux Programming forums, part of the Platform Specific Boards category; I am using mknod to stream some data from a program. I am trying to read that data in another ...

  1. #1
    Thinker
    Guest

    mknod FIFO

    I am using mknod to stream some data from a program. I am trying to read that data in another program simultaniously. But it will not allow me to read that data until I exit the first program. Is there a way to stop the non-blocking feature in mknod FIFO.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,645
    This is not the correct behaviour for named pipes. You can try mkfifo(). This is a POSIX compliant function and should behave properly.

    gg

  3. #3
    Thinker
    Guest
    I meant I need it to stop the blocking feature and turn on the non-blocking feature.

    sorry

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,645
    Use O_NONBLOCK when you open() the pipe. Read more about it here

    gg

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,645
    mknod() is not POSIX, it is System V - and even then (as you point out) it is only portable when used for named pipes on System V systems. POSIX only mentions mknod() in passing, it does not define it and therefore is not POSIX. (Read the "conforming to" section of your man pages.)

    POSIX only defines mknod as a shell commnd, not system call.

    mkfifo() is the only POSIX defined function for doing named pipes.

    If you use mkfifo(), when O_NONBLOCK is specified, an open for reading-only returns immediately and opening for writing-only will return an error if no process has yet opened the FIFO for reading.

    gg

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,645
    You'll also see that mknod() is an XSI extension and has just been added to the new base standard (IEEE Std 1003.1-2001, or POSIX.1:2001). XSI is an optional set of interfaces to the POSIX standard:
    [Definition for:]XSI
    The X/Open System Interface is the core application programming interface for C and sh programming for systems conforming to the Single UNIX Specification. This is a superset of the mandatory requirements for conformance to IEEE Std 1003.1-2001.
    As you can see, just because a function is in the the document doesn't mean that a POSIX.1:2001 conformant implementation will support it.

    You will also see in the doc:
    The mkfifo() function is preferred over this [mknod()] function for making FIFO special files.
    I think we can all agree that mkfifo() is the better function to use.

    You're right though, using man pages to quote what is and ain't current POSIX ain't right

    gg

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,645
    The strange behavior that Thinker first described suggested to me that mknod() was not handling named pipes correctly (of courese it could of been a bug in his code). Sure, if the platform implements both and the documentation says mknod() will do named pipes - then lets figure out whats wrong with the code (or if the documentation is wrong).

    For the benefit of other readers, here is a table containing all functions in the new POSIX.1:2001, which also shows their availability in other standards like classic POSIX.1 and POSIX.2, UNIX98, UNIX95, ISO C, SVID3 and 4.3BSD. (Columns with "P92" and "P96" are classic POSIX.2 and POSIX.1, respectively). Very usefull if you are trying to achieve some level of portability. You may also view/dowload POSIX.1:2001 (also called the Single UNIX Specification, Vol. 3) at the same site.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. select system call with FIFO fd.
    By vlrk in forum Linux Programming
    Replies: 0
    Last Post: 05-11-2009, 04:27 AM
  2. simultaneously waiting for data on FIFO and UDP using select call
    By yogesh3073 in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-05-2007, 08:53 AM
  3. working with FIFO files
    By icebabe in forum C Programming
    Replies: 6
    Last Post: 05-06-2006, 11:35 AM
  4. help! fifo read problem
    By judoman in forum C Programming
    Replies: 1
    Last Post: 08-16-2004, 09:19 AM
  5. FIFO list
    By Lillian176 in forum C Programming
    Replies: 4
    Last Post: 04-13-2003, 10:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21