bash io-redirection stderr – Does ‘Segmentation Fault’ Message Come Under STDERR?

bashio-redirectionstderr

I ran an executable in bash

./code > log

It shows occasional error messages on terminal whereas all printf statements go into log file. I re-run it like below

./code >& log

Now, the occasional error messages also go into log. But if there is a segmentation fault, it is still shown on terminal. Why? How to make the message Segmentation fault (core dumped) go into the log file?


user$ bash –version

GNU bash, version 4.2.24(1)-release (i686-pc-linux-gnu)

Best Answer

A segmentation fault is a signal, if you are not catching this then your program will be terminated and your shell will print this to its stderr (rather than your program's stderr).

It is possible for either your program or the shell to take specific actions when this occurs, either by the program catching the signal or your shell trapping the SIGCHILD signal and then checking your child's exit status.

Related Question