I'm not sure, but I think the shell has not yet updated the value of $? during a handler call for CHLD . Consider this script:
set -bm trap 'echo "Trap result code $?"' CHLD echo "Script: starting program" (exit 9) (exit 11) echo "Script: result code from program was $?"
I will replace your C ++ program with a simple subshell that mimics a seg error. When I run it, the CHLD trap prints "Result code 9" Trap ", indicating that the trap sees the exit status of the command before the one that starts the trap. Changing the value of the first subshell call to exit changes the value printed by the trap.
The question you associate with exit pseudo-signal traps. Without diving into the bash source, I suspect this is happening:
In step 2b, the value of $? corresponding to the command in 2a is not yet available. $? value $? available in step 3 $? related to the script, as it matches the value from 2c, from the last command executed in the script.
source share