Bash Trap Problem?

Hey all, I'm a fairly new shell scripter (been writing some very basic stuff for a couple of years once in a blue moon).

I have the need to start 2 or 3 processes from within a bash script when it's run then have the script kind of hang out and wait for the user to ctrl+c and when that happens the 2 or 3 running processes should be terminated and the script should continue.

I have a lot of the script written but am stuck at this point. I think I need to grab the PID #'s of the running processes using $$ or something then when CTRL-C is hit, send them a kill type signal but I've read a lot and message around with the trap command and can't seem to get it working right. Basically it would like like this.

./run_script.sh

Process 1 starts
Process 2 starts
Process 3 starts

Wait for user to hit [CTRL+C]...

[ctrl+c] is pressed

Process 1 ends
Process 2 ends
Process 3 ends

Script continues..

Any help you can give would be appreciated.
Thanks!
JS

#!/bin/sh
a=0
b=0
c=0
trap "kill $a $b $c", INT
script1.sh &
a=$!
script2.sh &
b=$!
script3.sh &
c=$!
wait
# the trap will resume here if the jobs all complete early, the script
# go on from  here as well
# .........more commands
exit

Great, thanks Jim, I'll try that. As a follow-up, your code assumes that all 3 of these processes will be running. In actuality, the beginning of my script is a bit interactive in that it first asks the user whether or not they want process 1/2/3 to run.

Having said that, I'm thinking that this trap would try and kill a process that may or may not be running, how might it be modified to first check if that particular process is running (e.g., the user answered Yes to that question at the beginning) and if so, then issue the kill?

Regards,
JS

Use a case statement, keep track of the number of processes you intend to create, based on user input: note move the trap statement can be anywhere before the wait statement, that way you know how many processes have been created.

t=1
case $t in
  1) trap  "kill $a ", INT       ; break;;
  2) trap  "kill $a $b ", INT    ; break;;
  3) trap  "kill $a $b $c", INT  ; break;;
  *) exit 2;;
esac