Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the STDOUT buffer?

Tags:

c

linux

As we know, STDOUT is buffered in Linux. My question is: 1) is it a global buffer shared by all processes? or one buffer for each process? 2) where the buffer is? on stack, or heap or static area? 3) who creates it?

like image 893
Dagang Avatar asked Feb 18 '13 10:02

Dagang


1 Answers

stdout is a C FILE pointer created by the standard library, so the relevant code is loaded as part of your C library. On Linux, it will be implemented in terms of Posix file descriptors.

Both your C library and the kernel may use buffering; you'll have to check the individual documentations. I recommend to start by looking at the relevant part of the source code of the C library (i.e. the part that implements <stdio.h>), which should be very educational.

like image 101
Kerrek SB Avatar answered Sep 27 '22 23:09

Kerrek SB