From ca6bde9e1c43cb839d974be583e9b05069b4906a Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 7 Feb 2024 10:05:37 -0800 Subject: [PATCH] top -b: add missing flush. We need to flush after each batch in batch mode. (Found by inspection, looking for sleeps similar to the vmstat one.) --- toys/posix/ps.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/toys/posix/ps.c b/toys/posix/ps.c index e4a69a4f..b99fa183 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -1742,13 +1742,15 @@ static void top_common( if (timeout<=now) timeout = new.whence+TT.top.d; if (timeout<=now || timeout>now+TT.top.d) timeout = now+TT.top.d; + fflush(stdout); + // In batch mode, we ignore the keyboard. if (FLAG(b)) { msleep(timeout-now); // Make an obvious gap between datasets. xputs("\n\n"); break; - } else fflush(stdout); + } recalc = 1; i = scan_key_getsize(scratch, timeout-now, &TT.width, &TT.height); -- 2.39.2