Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Jan 2016 18:08:44 +0000
From:      "Montgomery-Smith, Stephen" <stephen@missouri.edu>
To:        Yuri <yuri@rawbw.com>, "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>
Subject:   Re: How to send EOF to the popen(3) pipe?
Message-ID:  <569A872C.2010806@missouri.edu>
In-Reply-To: <569A8508.80908@rawbw.com>
References:  <5699BAC9.3060407@rawbw.com> <5699C8AB.7070006@missouri.edu> <569A8508.80908@rawbw.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 01/16/2016 11:59 AM, Yuri wrote:
> On 01/15/2016 20:35, Montgomery-Smith, Stephen wrote:
>> Maybe I am displaying my ignorance.  But wouldn't you do this by
>> invoking the function pclose?
>=20
> No, pclose kills the process and returns the exit code. Half-closed
> connection though can be alive for a while, until the other side
> finishes and closes the pipe.
>=20
>> My memory of using this was that this could gridlock because of
>> buffering.  Suppose process A popens a process B.  A sends a message to
>=20
> Gridlocks are possible if reads/writes are performed in the wrong order.
> But this is besides the point of the original question.
>=20
> I think the answer to my question is "no". popen(3) can't send EOF.
> Protocol needs to support EOF signal on the application-level.

Yes.  I think a "proper" implementation would be via a function like
popen2 https://emergent.unpythonic.net/01108826729, which creates 2 file
handles, not just one.  Then to send the EOF, you would close one of the
file handles (the "to_child"), and then only close the other file handle
(the "from_child") when it receives an EOF.

For the popen2 code to be compatible with stdio, you should run fdopen
on each file descriptor to create FILE*s.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?569A872C.2010806>