I need to check from a running C program whether stdout was deleted.
By "deleted" I mean a situation when in /proc/pid/fd is written "deleted":
ll /proc/91495/fd total 0 dr-x------ 2 ibse ibse 0 січ 31 00:49 ./ dr-xr-xr-x 9 ibse ibse 0 січ 31 00:49 ../ lrwx------ 1 ibse ibse 64 січ 31 00:49 0 -> '/dev/pts/5 (deleted)' lrwx------ 1 ibse ibse 64 січ 31 00:50 1 -> '/dev/pts/5 (deleted)' This can happen, for example, when the program's control terminal has been killed/closed.
Is there a way to check this without writing to stdout and checking the returned error?
I assumed that using fstat(STDOUT_FILENO, &buf) in this case would return an error, but this is not the case.