From nobody Tue Apr 04 05:36:14 2023 X-Original-To: questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PrGhg3zb4z43xhR for ; Tue, 4 Apr 2023 05:36:19 +0000 (UTC) (envelope-from guru@unixarea.de) Received: from ms-10.1blu.de (ms-10.1blu.de [178.254.4.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4PrGhg1pW3z4QWZ for ; Tue, 4 Apr 2023 05:36:19 +0000 (UTC) (envelope-from guru@unixarea.de) Authentication-Results: mx1.freebsd.org; none Received: from [188.174.48.200] (helo=pureos) by ms-10.1blu.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pjZL6-0002i7-3p; Tue, 04 Apr 2023 07:36:16 +0200 Date: Tue, 4 Apr 2023 07:36:14 +0200 From: Matthias Apitz To: Pete Cc: Christian Weisgerber , questions@freebsd.org Subject: Re: Clogged pipe? Message-ID: Reply-To: Matthias Apitz References: List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Operating-System: FreeBSD 13.0-CURRENT r368166 (amd64) X-message-flag: Mails containing HTML will not be read! Please send only plain text. X-Con-Id: 51246 X-Con-U: 0-guru X-Originating-IP: 188.174.48.200 X-Rspamd-Queue-Id: 4PrGhg1pW3z4QWZ X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:42730, ipnet:178.254.0.0/19, country:DE] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N El día lunes, abril 03, 2023 a las 08:38:15 -0700, Pete escribió: > So, I guess the short answer is that cat -n does block buffering to the > pipe, but cat with no options does not. > > tail -f testfile | cat | sed -u 's/^/X/' > tail -f testfile | cat -u | sed -u 's/^/X/' > tail -f testfile | cat -nu | sed -u 's/^/X/' > > all provide immediate output, but > > tail -f testfile | cat -n | sed -u 's/^/X/' > > does not and waits. I fired this up on Linux and used strace to look what the processes are doing: tail -f testfile | cat -n | sed -u 's/^/X/' X 1 11111111111 X 2 22222222222 X 3 33333333333 (hangs) ps ax | egrep ' tail| cat| sed' 25014 pts/2 S+ 0:00 tail -f testfile 25015 pts/2 S+ 0:00 cat -n 25016 pts/2 S+ 0:00 sed -u s/^/X/ srap53dxr1:/home/sisis/install # strace -p 25016 strace: Process 25016 attached read(0, ^C strace: Process 25016 detached srap53dxr1:/home/sisis/install # strace -p 25015 strace: Process 25015 attached read(0, ^C strace: Process 25015 detached srap53dxr1:/home/sisis/install # strace -p 25014 strace: Process 25014 attached select(5, [1 4], NULL, NULL, NULL i.e. the sed(1) and the cat(1) are just reading STDIN waiting for more input to appear. The problem is with the "tail -f" The -f flag let the tail(1) after it has read all the lines of "testfile" just waiting for the file cwto grow which could happen if other processes would write to the file. Nothing magic, wrong usage of -f here. matthias -- Matthias Apitz, ✉ guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045 Public GnuPG key: http://www.unixarea.de/key.pub No euro for the war! Keinen Euro für den Krieg! ¡No un Euro por la guerra!