How to kill all asynchronous processes

Posted by Arko on Stack Overflow See other posts from Stack Overflow or by Arko
Published on 2010-03-18T10:48:31Z Indexed on 2010/03/18 10:51 UTC
Read the original article Hit count: 184

Filed under:

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?

© Stack Overflow or respective owner

Related posts about bash