Re: using pipe



Hello,

I wanted to know if the "pipe" can only be used for data transmission from one process
to another (parent to child and viceversa) ?

Yes, pipe can be used as Inter-Process Communication (IPC) between
related processes.

Can a pipe be used to transfer data in the same prcoess ?

This could done, albeit this can be tricky.

For instance, I want to execute some function and want to save its
output to a pipe then in the same process, I need to read the output from this
pipe to some buffer (one string at a time). Can this be done ?

I beg your pardon. But why not using directly a buffer for that? The
function write its output to the buffer, and other functions may
retrieve the data from that buffer afterwards. That would be
definitively easier and more efficient than using a pipe.

Could you express the reasons behind that "pipe" choice?


Also, man page says that pipe returns two file descriptors ( and not
the FILE poiters to stream FILE *). How can I use fgets() to read the data
from the pipe ?

man 3 fdopen

Cheers,
Loic.

.



Relevant Pages

  • Re: select()/write() semantics
    ... I am writing about Linux 2.6 and Linux 2.6 does not ... select behaviour on FIFOs was discussed. ... if a buffer was added). ... to a set of pipe buffers. ...
    (comp.os.linux.development.apps)
  • Re: Make pipe data structure be a circular list of pages, rather than
    ... > work on socket locking than on pipe locking. ... > code should conceptually really allow one CPU to empty one pipe buffer ... > This is the main reason why I want to avoid coalescing if possible: ...
    (Linux-Kernel)
  • Re: Make pipe data structure be a circular list of pages, rather
    ... > the concept of actually keeping the buffer on an external controller. ... - depends on a fairly recent -BK (since it uses the pipe buffer ops ... # Still horribly bad VFS interface, ... # Need to pass in arrays of "struct pipe_buffer" ...
    (Linux-Kernel)
  • Re: select()/write() semantics
    ... So nothing about network connections turns into a *guarantee* ... process having access to this buffer can change anything about that. ... unsigned int mask; ... to a set of pipe buffers. ...
    (comp.os.linux.development.apps)
  • Re: select()/write() semantics
    ... terminate the connection. ... Because there is room in the pipe write buffer and nobody except the one ... unsigned int mask; ...
    (comp.os.linux.development.apps)