Flush the pipe/printf buffers externally for already running process with known PID
5
votes
3
answers
3080
views
I am writing a data logging app, all programs are started like:
./program > out.bin
The data collector periodically pools the stdout output files and reads the data.
The issue is that the IO streams are buffered and if some program outputs data in like 1 byte per second, it takes a lot of time (up too 4k seconds with default 4kB buffer size) before the data are actually flushed out.
My question is how to force the stdout/pipe/printf buffer to flush externally, i.e. call externally something like fflush(stdout)
.
I have read various sites like https://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe/25378 , but I can not disable the buffers as it have huge IO performace impact (measured).
I am looking for high performace solution for production and these following conditions are always met:
- the program (data producer) PID is always known
- the output is always a file with known path
- the data logging process has full root access
Asked by mvorisek
(251 rep)
Jun 10, 2019, 09:22 AM
Last activity: Apr 19, 2024, 11:35 AM
Last activity: Apr 19, 2024, 11:35 AM