Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setvbuf on STDOUT safe for other processes?

I am using HP-UX. I want to disable buffering on stdout to ensure that every line of code is printed in case of core dump with below command:

setvbuf(stdout, NULL, _IONBF, 0); // turn off buffering for stdout

In this case, does it also affect other processes printing to stdout which is being redirected to some log file ? I want to know if this change is only local to process being executed or not. Also, can i disable the buffering within the process and later on set it _IO_FBF again within the code ? (fflush before each call )

PS: I know this will disable buffering and have worse I/O performance, but i want to do this only for debugging purposes.

like image 534
rApt0r Avatar asked Jan 04 '12 15:01

rApt0r


People also ask

Which one of the following will turn off buffering for stdout?

Use fflush(stdout) . You can use it after every printf call to force the buffer to flush.

What is_ ionbf?

Macro: int _IONBF. The value of this macro is an integer constant expression that can be used as the mode argument to the setvbuf function to specify that the stream should be unbuffered.


1 Answers

The setvbuf call only affects stdio routines in the current process and any children fork'd but not exec'd.

How stdio responds when setvbuf is called multiple times on the same stream is not specified in the C standard, so do not issue multiple calls in code you want to be portable across C implementations.

like image 129
Kyle Jones Avatar answered Sep 21 '22 17:09

Kyle Jones