c/unix q

c/unix q

Amos Shapira amos.shapira at gmail.com
Tue Jun 4 15:18:34 IDT 2013


Bzzzzt. Wrong.

If the unused side of the pipe is left open by the process which doesn't
read it then it will be considered as "open" even if the other side closed
it, therefore preventing the reading process from receiving the EOF mark
(read(2) returning zero bytes).

And just to backup my claim above - see a more comprehensive response here:
http://stackoverflow.com/a/976087


On 4 June 2013 21:43, ronys <ronys at gmx.net> wrote:

> Nothing. You're just wasting resources (file descriptors) and making your
> code a bit harder to understand and maintain.
>
> Note that for pipe(), you can use both fds at both ends of the pipe, but
> it's very easy to get into a race condition.Better to open a pair of pipes,
> one for each direction (of course, you now need to worry about
> deadlocks...).
>
> Rony
>
>
> On Tue, Jun 4, 2013 at 2:24 PM, Erez D <erez0001 at gmail.com> wrote:
>
>> hello
>>
>> using the usual pipe()+fork()+dup()+close() to fork a child process and
>> pipe data from and to it,
>>
>> I  know both the child and parent must close the unused fds.
>>
>> why ?
>> what if i don't close the unsed fds ?
>>
>>
>> thanks,
>> erez.
>>
>>
>> _______________________________________________
>> Linux-il mailing list
>> Linux-il at cs.huji.ac.il
>> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>>
>>
>
>
> --
> Ubi dubium, ibi libertas (where there is doubt, there is freedom)
>
> _______________________________________________
> Linux-il mailing list
> Linux-il at cs.huji.ac.il
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>
>


-- 
 [image: View my profile on LinkedIn]
<http://www.linkedin.com/in/gliderflyer>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20130604/548ba7ac/attachment.html>


More information about the Linux-il mailing list