Are open streams automatically flushed and closed on SIGINT in C?

The C99 spec 7.19.3 has a weaker guarantee.

The C99 spec 7.19.3 has a weaker guarantee: 5 If the main function returns to its original caller, or if the exit function is called, all open files are closed (hence all output streams are flushed) before program termination. Other paths to program termination, such as calling the abort function, need not close all files properly. 4 A file may be disassociated from a controlling stream by closing the file.

Output streams are flushed (any unwritten buffer contents are transmitted to the host environment) before the stream is disassociated from the file. So in C99, if it's closed then it's flushed. The POSIX exit function has more details, in particular that whether _exit closes streams is implementation defined.

You'll have to handle the signal if you want your buffers flushed. Otherwise the process will be terminated and the file descriptors closed without flushing the stdio buffers.

This is correct. By default, a SIGINT will terminate the process abnornally. Processes so terminated do not call exit() and so do not have buffers flushed.

– Steve Emmerson Jan 11 '10 at 19:52 How do you know this? – Ollie Saunders Jan 11 '10 at 20:22 Flushing buffers from a signal handler invokes undefined behavior in almost all cases. The only way it wouldn't is if you can ensure that no async-signal-unsafe functions could be executing at the time the signal occurs.

– R.. Mar 22 at 5:49.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions