I have an unsuccessful C program, and I narrowed it down to an fork()ed child trying to close stdout and stderr that were closed by its parent process before the call fork()- I assume that these threads were passed to the child process.
fork()
how can I determine if a thread is closed in C before trying to close it using something like fclose(stdout)
fclose(stdout)
C programs on UNIX suggest that you start will be open file descriptors 0, 1 and 2. If you do not want them to go anywhere, go /dev/nulland dupfor these file descriptors.
/dev/null
dup
, , , FILE C (stdin co), .
FILE
stdin
, , lseek(fd, 0, SEEK_SET) , , .
lseek(fd, 0, SEEK_SET)
ftell(), . -1, .
fclose() undefined.
, FILE * stdout, stdout, , /.
stdout
stdout , fd 1.
struct stat stbuf; if(fstat(1,&stbuf) == -1) { if(errno == EBADF) { stdout isn't open/valid } }
Source: https://habr.com/ru/post/1735186/More articles:Где мои конструкторы WCF-клиента перегружены? - constructorImage Conversion: RGBA to RGB - c ++PHP Accelerators and Static Fields - phphow to specify phone number in geocoding - pythonCreating a cross-platform C ++ library - c ++Web form with over 100 fields - webformsSwitching to Visual Basic on Perl - working with user interfaces - user-interfaceHow to use NSNumberFormatter to print currency in UITextField - iphoneКак я могу отправить вызов делегату, тип которого не завершен во время испускания? - reflectionкак изменить форму кнопки - c#All Articles