Suppose we have a BASH script running some commands in the background. At some time we want to kill all of them, whether they have finished their job or not.
Here's an example:
function command_doing_nothing () {
sleep 10
echo "I'm done"
}
for (( i = 0; i < 3; i++ )); do
command_doing_nothing &
done
echo "Jobs:"
jobs
sleep 1
# Now we want to kill them
How to kill those 3 jobs running in the background?