If you have a shell script that runs a lot of jobs in the background, you will want to clean these processes up at the end of the execution ( say the user hits CTRL-C or kills the job). To do so is fairly easy if you know how to do it. No need to keep track of pids, just do kill 0 as part of the signal trap execution. eg.

#!/bin/bash

trap "kill 0" SIGINT SIGTERM

runprogram &
otherprogram &

wait

Found at: stackoverflow.com