I'm using /usr/bin/time
to report information about a set of benchmarks I'm running. The interesting data points are runtime, memory usage and the exit status. This works fine except when the application fails with an uncaught exception, in which case /usr/bin/time
reports a 0
exit code instead of the actual 134
.
Let me illustrate the problem with a toy example for the app:
#include <stdexcept>
int main(int argc, char** argv) {
throw std::runtime_error("test"); // 1
//return 134; // 2
}
and the following call:
/usr/bin/time -f "%x" ./app ; echo $?
.
Throwing the error (line 1 not commented) results in the following output:
terminate called after throwing an instance of 'std::runtime_error'
what(): test
Command terminated by signal 6
0
134
whereas actually returning the exit status (line 2 not commented) works:
Command exited with non-zero status 134
134
134
/usr/bin/time --version
reports an UNKNOWN
version, but I see the same behavior on Ubuntu 20.04 and 22.04.
I suspect it has something to do with the SIGABRT (signal 6), but I cannot find a fix or an explanation for the behavior.
How can I get /usr/bin/time
to report the correct exit status in cases of uncaught exceptions?