Description:
A non-interactive shell that receives SIGINT while it waits for a
child (command substitution or a foreground external command) can
livelock at 100% CPU, forever, even when SIGINT is ignored with
trap '' INT.
strace of the stuck process shows this loop, with si_pid equal to
the shell's own pid:
--- SIGINT {si_signo=SIGINT, si_code=SI_USER, si_pid=<self>} ---
getpid() = <self>
kill(<self>, SIGINT) = 0
rt_sigreturn({mask=[CHLD]}) = 0
... repeats ...
Our reading of jobs.c (5.3, wait_for, around line 3093): when
job_control == 0 || (subshell_environment & SUBSHELL_COMSUB), the
code does
temp_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler);
if (temp_sigint_handler == wait_sigint_handler)
...
else
old_sigint_handler = temp_sigint_handler;