/* Compile: cc -G isatty.c -o isatty.so -Kpic gcc -shared -o isatty.so isatty.c * Use: env LD_PRELOAD=./isatty.so cmd * Why: This is a sample C program: #include main(argc, argv) int argc; char **argv; { int c; while ( (c=getchar()) != EOF ) { putchar(c); } } It uses the following shared libraries: $ ldd mi_cat libc.so.1 => /usr/lib/libc.so.1 libdl.so.1 => /usr/lib/libdl.so.1 libc.so.1 has a function _isatty which will test if the output is a tty, and then decide if to use buffer. $ nm /usr/lib/libc.so.1 | grep isatty [3281] | 247552| 71|FUNC |GLOB |0 |12 |_isatty [4400] | 247552| 71|FUNC |WEAK |0 |12 |isatty [1394] | 0| 0|FILE |LOCL |0 |ABS |isatty.c LD_PRELOAD forces the C program to use preloaded version of _isatty which return 1 indicating it is tty though it may not be. This forces non-buffering. */ _isatty(int fd) { return 1;}