top | grep --line-buffered chromium >> load.log
When grep writes to a tty its output is line buffered. When it's redirected to a file its output is fully buffered, meaning it only flushes every 4096 bytes. The --line-buffered
option overrides this behavior, forcing it to flush stdout after every line.
This behavior isn't unique to grep; it can happen with any standard C program that uses libc. You can use stdbuf
to force an arbitrary program to be line-buffered.
top | stdbuf -oL grep chromium >> load.log