fd = file descriptor.
What kind of checks? Well for starters possibly
timing out and cleaning up all allocated resources
or using even the ancient signal(man signal), to
catch those sigTERM ,etc, and cleaning up responsibly.
It's easier to explain this way:
Say I have a program that opens stdin, gets input
does some other stuff, and does it all again until a certain condition is met, but does no signal handling
or anything a more mature program should do.
int main(void) {
int y = 0,p;
FILE *efile;
char buf[50];
if ( (efile = fopen("/logfilepath","r"

) != NULL) {
while (1) {
y++;
fprintf(stdout,"%s\n", "File entry"

;
fflush(stdout);
fgets(buf,50,stdin);
p = do_commit_query(efile,buf);
if (p == 2) {
fclose(efile);
exit(1);
} else if (p == 1) {
fclose(efile);
return 0;
}
}
}
perror("fopen()"

;
exit(1);
}
What happens when I run this through telnet and then
exit the controlling session, say by closing the xwindow
I was running it in, or by sending ctrl-c to telnet?
This kind of thing invokes undefined behavior. Will
telnet be able to cleanup all processes when they don't
relinquish the tty? Possibly, but that's not it's real
function. What will the kernel do with the login and
shell associated processes if telnet exits cleanly
and the program does not? We can see that in your
example I think.
"Can you elaborate? I don't know what you're talking
about."
If you are not the program writer and are unable to
fix the code, or are unable to wrap the whole session
in some sort of
wrapper , then
you could possibly follow mrregan's advice.
Otherwise you just have a misbehaving c program that
does bad things and leaves you to clean up.
This is not unheard of believe me

..