bash: silently kill background function process
Just came across this myself, and realised "disown" is what we are looking for.
foo &foo_pid=$!disownboring_and_long_commandkill $foo_pidsleep 10
The death message is being printed because the process is still in the shells list of watched "jobs". The disown command will remove the most recently spawned process from this list so that no debug message will be generated when it is killed, even with SIGKILL (-9).
This "hack" seems to work:
# Some trickery to hide killed messageexec 3>&2 # 3 is now a copy of 2exec 2> /dev/null # 2 now points to /dev/nullkill $foo_pid >/dev/null 2>&1sleep 1 # sleep to wait for process to dieexec 2>&3 # restore stderr to savedexec 3>&- # close saved version
and it was inspired from here. World order has been restored.