I have a C program that uses PIPES to communicate with an external application.
I use EXECL for this:
execl("./errorprogram","./errorprogram", NULL);
Now I have also used DUP2 to redirect all STDERR to the writing end of the pipe
dup2(fd[1], STDERR_FILENO);
And if I test that using a simple Python script like:
data = sys.stdin.read()
sys.stderr.write("Bad error
")
I can happily read that error back in the "parent".
Now for my issue: Let's say I have a C "child program" that has a memory leak in it or an "invalid pointer" error like:
#include<stdio.h>
#include<string.h>
void main (){
char szInput[1024];
char *badvar;
gets(szInput);
badvar = realloc(badvar, 100);
puts(szInput);
fflush(NULL);
}
The REALLOC statement above is purposely there to cause the program to die, and I will get an error like the following at runtime (obvioulsy the PARENT is not affected, only the CHILD process):
* glibc detected ./error: realloc(): invalid pointer: 0xb77a5250 **
And a whole stace trace etc....
Now how can I get any runtime errors like this to STDERR so I can read the full trace back into the parent?
Do I have to redirect "runtime errors to STDERR"? Surely it is possible to catch these hectic errors raised from the child so that the parent can log them etc?
Any help or advise would be greatly appreciated ;-)
Thanks
Lynton
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…