Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Jan 2016 03:44:18 +0700
From:      Eugene Grosbein <eugen@grosbein.net>
To:        Yuri <yuri@rawbw.com>, Freebsd hackers list <freebsd-hackers@FreeBSD.org>
Subject:   Re: How to send EOF to the popen(3) pipe?
Message-ID:  <569AABA2.8010505@grosbein.net>
In-Reply-To: <5699BAC9.3060407@rawbw.com>
References:  <5699BAC9.3060407@rawbw.com>

next in thread | previous in thread | raw e-mail | index | archive | help
16.01.2016 10:36, Yuri wrote:
> Is there a way to send the EOF to popen(3) pipe?
>
> Imagine the situation when the child process works in a stream fashion,
>processes objects one by one, and stops on EOF from stdin.
> One has to be able to send EOF to get to the end of the last processed object.
>  Otherwise reading from the descriptor will generally block.

You can use pipe2(), then vfork(), then close reading descriptor in child process,
then just execv() for shell. In parent process, close writing descriptor before
beginning of reading cycle. So, the subprocess can just fclose() its output
and parent gets zero bytes read next time, that is EOF.

Eugene Grosbein



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