I have a C ++ program that I use to verify that another program is not crashing. Parent code (we will call it parentProg) looks something like this:
int run(const char * command) { ... int retCode = system(command); printf("Code is %d\n",retCode); if(retCode == 134)
The command variable contains the program under test (we will call it "childProg"). With the previous Linux distribution, this code worked as expected. If a.out crashes or hits a statement, it will return 134, and the error handling code will work. However, after I switched to the new Linux distribution, this is no longer the case. Instead, I see a return code of 6 when I run as the created program using GDB or nemiver. Oddly enough, it returns to 134 if I run the child program myself or using DDD.
For the following tests, I modified childProg only as the following code:
#include <assert.h> int main(int argc, char * argv[]) { assert(0); return 0; }
childProg in itself
[ user@localhost multi]$ ./childProg childProg: temp.cpp:5: int main(int, char **): Assertion `0' failed. Abort [ user@localhost multi]$ echo $? 134
parentProg that spawns childProg
[ user@localhost multi]$ ./parentProg 1 o Running 1 times childProg: temp.cpp:5: int main(int, char **): Assertion `0' failed. Code is 6 Done 0 [ user@localhost multi]$
With gdb
(gdb) run Starting program: parentProg 1 o Running 1 times Detaching after fork from child process 3311. childProg: temp.cpp:5: int main(int, char **): Assertion `0' failed. Code is 6 Done 0 [Inferior 1 (process 3295) exited normally] (gdb)
With DDD
(gdb) run 1 o Starting program: parentProg 1 o Running 1 times Detaching after fork from child process 3336. childProg: temp.cpp:5: int main(int, char **): Assertion `0' failed. Code is 134 Done 0 [Inferior 1 (process 3319) exited normally] (gdb)
It works as expected.
[ me@localhost multi]$ /bin/sh -c ./childProg childProg: temp.cpp:5: int main(int, char **): Assertion `0' failed. Abort [ me@localhost multi]$ echo $? 134
What could be here? Is there a better way to check for failures / segfaults / assertions besides checking the exit code?