I have a failing C program, and i’ve narrowed it down to a fork()ed child trying to close stdout and stderr, which were closed by its parent process before calling fork() – i assume those streams were passed on to the child process.
how can i tell if a stream is closed in C before attempting to close it using something like fclose(stdout)
C programs on UNIX expect to have a file descriptors 0, 1 and 2 open when they are started. If you do not want them to go anywhere, open
/dev/nullanddupit to those file descriptors.