Interesting. I've always wondered why there wasn't an addition in/out fd pair for communicating with the previous/next program in a chain of pipe, e.g:
foo | bar
STDOUT --> STDIN
ALTIN <-- ALTOUT
You could detected it by looking for specially number fd's open on program launch, or maybe an environment variable.