I've read in a man page that when exit()
is called all streams are flushed and closed automatically. At first I was skeptical as to how this was done and whether it is truly reliable but seeing as I can't find out any more I'm going to accept that it just works — we'll see if anything blows up. Anyway, if this stream closing behavior is present in exit()
is such behavior also present in the default handler for SIGINT
(the interrupt signal usually triggered with Ctrl+C)? Or, would it be necessary to do something like this:
#include <signal.h>
#include <stdlib.h>
void onInterrupt(int dummy) { exit(0); }
int main() {
signal(SIGINT, onInterrupt);
FILE *file = fopen("file", "a");
for (;;) { fprintf(file, "bleh"); } }
to get file
to be closed properly? Or can the signal(SIG...
and void onInterrupt(...
lines be safely omitted?
Please restrict any replies to C, C99, and POSIX as I'm not using GNU libc. Thanks.