From owner-freebsd-current@freebsd.org Sun Mar 5 04:13:01 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F395BCF81FA for ; Sun, 5 Mar 2017 04:13:00 +0000 (UTC) (envelope-from alfred@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [IPv6:2001:470:1f05:b76::196]) by mx1.freebsd.org (Postfix) with ESMTP id E004C12D8; Sun, 5 Mar 2017 04:13:00 +0000 (UTC) (envelope-from alfred@freebsd.org) Received: from Alfreds-MacBook-Pro-2.local (unknown [IPv6:2601:645:8003:a4d6:f0bd:4880:531f:5558]) by elvis.mu.org (Postfix) with ESMTPSA id 85D53346DE67; Sat, 4 Mar 2017 20:13:00 -0800 (PST) Subject: Re: Fwd: Re: I/O semantics of pipe and FIFO. To: Julian Elischer , freebsd-current , Devin Teske References: <20170304214812.GA16845@chaz.gmail.com> <8efdc961-1768-0bc0-715f-4a1e103359d4@elischer.org> From: Alfred Perlstein Organization: FreeBSD Message-ID: <17381773-019a-2181-f00f-1908d04b8d22@freebsd.org> Date: Sat, 4 Mar 2017 20:12:59 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <8efdc961-1768-0bc0-715f-4a1e103359d4@elischer.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Mar 2017 04:13:01 -0000 Devin and I found this when we worked together. I think it was due to some situation in dd(1) where short reads would exit pre-maturely, however I may be mis-remembering. Devin, do you recall the specifics? On 3/4/17 7:44 PM, Julian Elischer wrote: > > an interesting point to discuss? is our behaviour in this test right? > from: "austin-group mailng list (posix standard discussion)" > > ------ rest of email is quoted ------- > On 5/3/17 5:48 am, Stephane Chazelas wrote: > > 2017-03-04 13:14:08 +0000, Danny Niu: >> Hi all. >> >> I couldn't remember where I saw it saying, that when reading >> from a pipe or a FIFO, the read syscall returns the content of >> at most one write call. It's a bit similar to the >> message-nondiscard semantics of dear old STREAM. >> >> Currently, I'm reading through the text to find out a bit >> more, and I appreciate a bit of pointer on this. > [...] > > (echo x; echo y) | (sleep 1; dd count=1 2> /dev/null) > > outputs both x and y in all of Linux, FreeBSD and Solaris in my > tests. > > That a read wouldn't read what's currently in the pipe would be > quite surprising. > > I also wouldn't expect pipes to store the writes as individual > separate message but use one buffer. > > In: > > ( > dd bs=40000 count=1 if=/dev/zero 2> /dev/null > echo first through >&2 > dd bs=40000 count=1 if=/dev/zero 2> /dev/null > echo second through >&2 > ) | (sleep 1; dd bs=100000 count=1 2> /dev/null) | wc -c > > That is where the second write blocks because the pipe is full, > the reading dd still reads both writes in Linux and Solaris in > my tests (on Solaris (10 on amd64 at least), reduce to 20000 > instead of 40000 or both writes would block). > > On FreeBSD, I get only the first write (using 8000 followed by > 10000 for instance). > > FreeBSD is also the only one of the three where > > dd bs=1000000 count=1 if=/dev/zero | dd bs=1000000 count=1 | wc -c > > Doesn't output 1000000. The others schedule both processes back > and forth during their write() and read() system call while the > pipe is being filled and emptied several times. >