Interview Prep/Shell Scripting/Functions, exit codes, strict mode and traps

What does `wait` return when a background job is killed by a signal?

AdvancedConceptFunctions, exit codes, strict mode and traps
Answer

wait PID returns 128 + signal number, the same convention as a foreground command. If the PID is not a child of this shell, it returns 127 with wait: pid N is not a child of this shell.

sleep 100 & pid=$!
kill -TERM "$pid"
wait "$pid"; echo $?     # 143

Note that $! refers to the last background job only; store PIDs in an array as you start jobs.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Functions, exit codes, strict mode and traps