bash: silently kill background function process bash: silently kill background function process unix unix

bash: silently kill background function process


kill $foo_pidwait $foo_pid 2>/dev/null

BTW, I don't know about your massively cool progress bar, but have you seen Pipe Viewer (pv)? http://www.ivarch.com/programs/pv.shtml


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.