Skip to content

Instantly share code, notes, and snippets.

@vaughnd
Created September 21, 2012 06:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaughnd/3759951 to your computer and use it in GitHub Desktop.
Save vaughnd/3759951 to your computer and use it in GitHub Desktop.
Bash script to run more than one process in parallel and kill all when exiting the script (via ctrl-c or kill)
#!/bin/bash
# kill all subshells and processes on exit
trap "kill 0" SIGINT
# start commands in subshells so all their spawn DIE when we exit
( process1 ) &
( process2 ) &
wait
@1453055
Copy link

1453055 commented Jun 7, 2018

it's really useful, thank you

@gabrielhuang
Copy link

Exactly what i needed thanks!

@storenth
Copy link

Do we need set -m on the top of the script in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment