+5  A: 
foo & pid_foo=$!
bar & pid_bar=$!

wait $pid_foo
kill $pid_bar

But perhaps you could just run foo | bar (if that happens to work with stdin/stdout handling).

ndim
The pipe is clever but perhaps you don't want the stdin/stdout consequences
frankc
you don't need the pids, you can use %1, %2
Patrick
@Patrick: If the processes are actually just numbered, that might make sense. In the general case, though, it makes more sense to name the variables `pid_foo` and `pid_bar`, and that is more clear when reading the code than `%1` and `%2`. However, thanks for mentioning that this possibility exists (at least in bash).
ndim
No need for intermediate variables:You can name your processes: kill %foo
Jürgen Hötzel
+1  A: 
#!/bin/bash 

#enable job control in script
set -m

producer &

consumer &

fg %1

kill %2
frankc