How to redirect RUNTIME ERRORS to STDERR?

后端 未结 2 816
栀梦
栀梦 2021-01-06 12:23

I have a C program that uses PIPES to communicate with an external application.

I use EXECL for this:

execl(\"./errorprogram\",\"./errorprogram\", N         


        
2条回答
  •  生来不讨喜
    2021-01-06 12:53

    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.

提交回复
热议问题