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.
link|improve this question

78% accept rate
feedback

2 Answers

up vote 5 down vote accepted

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
link|improve this answer
feedback
# script
command &
# more script
wait
link|improve this answer
With that, pressing ^C exits the script, but leaves the blocking process still running, on my system (Mac OS X). – f100 Jan 10 '10 at 11:36
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.