I'm trying to build a start script and a stop script for my project. I need to run a sass auto-compiler as well as a server, and redirect the output of both to a file. I'm using
# Start a sass watcher and a server running simultaneously. Store the PIDs in a
# text file so that the processes can be easily stopped.
echo $! > .pids.txt &
sass --watch sass:css --style=compressed &
echo $! >> .pids.txt &
) &> log.txt
kill $(cat .pids.txt)
You could store them in an array, if that's what you wouldn't call hackish.
EDIT: Another way is to just execute:
kill $(jobs -p)
This kills all background processes (jobs -p prints the PIDs of all background process to stdout, which are then handed to kill).