Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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
share|improve this answer
# script
command &
# more script
wait
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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