# define trap function
child_handler() {
  pid="$1"
  status="$2"
  echo "child ${pid} exited with status ${status}"
}
trap 'child_handler ${pid} $?' CHLD

# fork subprocess
some_child &
pid=$!

# wait on pid
wait "${pid}"
