Maybe this is totally flawed but it looks like a good idea to me:
https://blog.plover.com/Unix/stdio-buffering.html