Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Can't redirect segmentation fault error to file



On Oct 23,  7:06am, Ismail Donmez wrote:
}
} Suppose I have a crashing executable:
} 
} For some reason I want to redirect the segmentation fault error to a file.

The segmentation fault error isn't printed by the failing command, it's
printed by the shell when it is notified of the failed exit status of
the command.

Zsh sends job control messages to the "shell output" (typically the
terminal) rather than to standard error, so redirecting standard error
won't trap anything.

That said, I'm not entirely sure why it doesn't print anything at all:

torch% bash -c 'kill -SEGV $$'
zsh: segmentation fault (core dumped)  bash -c 'kill -SEGV $$'
torch% { bash -c 'kill -SEGV $$' }
torch% 

Braces suppress job exit status messages as far back as zsh 4.2.0 (maybe
farther).

One other thing -- I'm not sure why you're getting

[1]    6511 segmentation fault (core dumped)  ./a.out

when in your example the job does not appear to have been backgrounded.
The job number "[1]" should only appear like that for background jobs:

torch% bash -c 'kill -SEGV $$' &
[1] 7957
torch% 
[1]  + 7957 segmentation fault (core dumped)  bash -c 'kill -SEGV $$'

and in THAT case I get:

torch% { bash -c 'kill -SEGV $$' & } 2>err
[2] 7963
torch% 
[2]  + segmentation fault (core dumped)  bash -c 'kill -SEGV $$'
torch% cat err
torch% 

In 4.2 the job start message is printed to stderr, but the job termination
message is not:

zsh-4.2.0% { bash -c 'kill -SEGV $$' & } 2>err
zsh-4.2.0% 
[2]  + 7959 segmentation fault (core dumped)  bash -c 'kill -SEGV $$'
zsh-4.2.0% cat err
[2] 7959
zsh-4.2.0% 

So where the messages go is at least now consistent in 5.1.



Messages sorted by: Reverse Date, Date, Thread, Author