It does not always output to stdout, because by default stdout has BUFFERED output, and stderr does not load. In general, for a buffered output stream, the stream is not flushed until the system is βfreeβ for this. Thus, data can continue buffering for a long time before it is flushed. If you want to force a fflush , you can do it manually using fflush
#include<stdio.h> #include <unistd.h> int main(){ while(1) { fprintf(stdout,"hello-out"); fflush(stdout); /* force flush */ fprintf(stderr,"hello-err"); sleep(1); } return 0; }
Update: stdout is a linear buffer when connected to the terminal and simply buffers otherwise (e.g. redirection or channel)
source share