Your stdout has not been closed, so checking for this will be useless. Your program received SIGPIPE and quit. SIGPIPE is delivered whenever your program writes to a handset on which there are no readers. In your example, this happens when the head completes, closing it with stdin.
SIGPIPE should be ignored if you want your program to continue. This code ignores SIGPIPE:
(void)signal(SIGPIPE, SIG_IGN);
If you do not want to change your program, you can arrange for something to continue reading from the channel, even after head closes the input. 1
./a.out | ( head -n10 >dumped ; cat > /dev/null )
1 : The shell example is valid for bash, maybe not for csh.
source share