c/unix q

c/unix q

Amos Shapira amos.shapira at gmail.com
Tue Jun 4 15:23:38 IDT 2013


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...).
>

And about this one (race conditions) - any two processes using pipes (which
have limited buffer size) to talk to each other bi-directionally run the
risk of a deadlock if not coded carefully since they can easily reach a
point where both of them block on write(2) which will only unblock when the
other side read(2)'s and frees up space in the buffer (but the other side
is blocked on a write - that's why it's called a "deadlock"). Typical ways
to avoid that are to create threads to watch the fd's or use none-blocking
IO.


>
> 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/df9c7f02/attachment.html>


More information about the Linux-il mailing list