Where did my segfault go?
11 hours ago
- #segmentation fault
- #shell behavior
- #debugging
- A segmentation fault message is printed by the shell when it reaps a child process that died from SIGSEGV, not by the crashing program itself.
- When using commands like 'bash -c', bash may exec directly into the command without forking, preventing the shell from being the parent and printing the error.
- Using a wrapper script or forcing a subshell (e.g., with parentheses) ensures a shell is present as the parent to detect and report the segmentation fault.
- Adding a command after the crashing one (e.g., 'true') also prevents exec optimization, allowing the shell to print the error message.