#include
#include
int main(){
while(1)
{
fprintf(stdout,\"hello-out\");
fprintf(stderr,\"hel
You forgot newlines (noted \n
) in your strings. Or you need to call fflush(NULL);
or at least fflush(stdout);
before sleep(1);
And fprintf(stdout, ...)
is the same as printf(...)
You need to output newlines or to call fflush
because (at least on Linux) the stdout
FILE buffer is line-buffered. This means that the C library is buffering data, and will really output it (using the write Linux system call) when the buffer is full enough, or when you flush it either with a new line, or by calling fflush
. Buffering is needed because system calls are costly (calling write
for every byte to be output is really too slow). Read also the man page of setbuf