I have a C program that uses PIPES to communicate with an external application.
I use EXECL for this:
execl(\"./errorprogram\",\"./errorprogram\", N
By default, Glibc will produce output on the process's controlling terminal, if one exists. It sounds like you want to set the environment variable LIBC_FATAL_STDERR_=1
, which will instead send fatal errors to stderr always.
One possible solution if you are working on a system that supports signals, such as linux, is to use the signalling mechanism. Installing a signal action for invalid memory references (I believe this is the SIGSEGV signal) should, I think, catch the particular example you give above. In the handler you can then print error messages to STDERR as you wish. You would still need some way to determine the stack trace, however.