LIBSTDBUF(3)
π libstdbuf(3) β Library Functions Manual β¨
okay so picture this: a little library named libstdbuf, and its whole ~main character~ job is to change how standard input, standard output and standard error get buffered at startup. That's it. That's the gig. π
πΈ NAME πΈ
libstdbuf β a preloaded library to change standard streams' initial buffering. no cap, that's literally the entire name section, she's concise π
π¦ DESCRIPTION π¦
So the libstdbuf library is meant to be preloaded using the LD_PRELOAD environment variable β preloading it is the whole way it does its thing β so that it can change the initial buffering of the standard input, standard output, and standard error streams. β¨
Now, you can load and configure this library manually if you're feeling β¨manualβ¨ about it, but there's also a utility β stdbuf(1) β that runs a command with the appropriate environment variables already set up for you. So like, that's the easy button. π«Ά
π ENVIRONMENT π
Each stream gets configured independently through its own environment variable (and the values are defined right below, don't worry bestie):
_STDBUF_Iβ the initial buffering definition for the standard input stream π_STDBUF_Oβ the initial buffering definition for the standard output stream π_STDBUF_Eβ the initial buffering definition for the standard error stream π¦
And each one of those variables can take one of these values:
"0"β unbuffered πββοΈ"L"β line buffered β"B"β fully buffered, with the default buffer size πsizeβ fully buffered with a buffer of size bytes (and yes, the suffixes'k','M'and'G'are accepted) π₯
π EXAMPLE π
okay here's the vibe: in this example, the stdout stream of the awk(1) command will be fully buffered by default, because it does not refer to a terminal. (rude, but okay.) So libstdbuf is used to force it to be line-buffered, so that vmstat(8)'s output will not stall until the full buffer fills. icon behavior, honestly. β¨
# vmstat 1 | LD_PRELOAD=/usr/lib/libstdbuf.so \
STDBUF_1=L awk '$2 > 1 || $3 > 1' | cat -n
Copy that block character for character, bestie β I'm not touching a single letter of it. π
And if you want a simpler way to do this, see stdbuf(1). π
π§ SEE ALSO π§
π HISTORY π
The libstdbuf library first appeared in FreeBSD 8.4. a lil retro, we stan β
π AUTHORS π
The original idea of the libstdbuf command comes from Padraig Brady, who implemented it in the GNU coreutils. Jeremie Le Hen implemented it on FreeBSD. kings, both of them π«Άπ
so yeah, that's the whole page β this one came from Debian, dated June 29, 2023, and that's your sign-off bestie ππ go buffer responsibly β¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2012 Jeremie Le Hen <jlh@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms