0

Could you help me with the Bash syntax to achieve the following?

  1. Run a blocking process without blocking execution of the rest of the script.
  2. Run a standard "non-blocking" process (e.g. lsof).
  3. "Rejoin" the blocking process so that ^C will stop that process, then end execution of the script.
xyz
  • 501
  • 1
  • 7
  • 13

2 Answers2

4

Is this an idiomatic way to do it?

#!/bin/bash
function handle_int()
{
    kill $BCPID
    exit
}
trap handle_int INT

blocking_command &
BCPID=$!

non_blocking_command
wait
xyz
  • 501
  • 1
  • 7
  • 13
0
# script
command &
# more script
wait
gorilla
  • 1,207
  • 9
  • 6
  • With that, pressing ^C exits the script, but leaves the blocking process still running, on my system (Mac OS X). – xyz Jan 10 '10 at 11:36