bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Wanted: bash enhancement... non-blocking 'wait'


From: Philip Prindeville
Subject: Wanted: bash enhancement... non-blocking 'wait'
Date: Thu, 02 Sep 2010 15:44:28 -0700
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2

 I wanted to check in and see if there was a chance of this feature being 
accepted upstream before I spent any time on it...  so here goes.

The "wait [n]" command is handy, but would be even handier is:

wait [[-a] n]

instead, which asynchronously checks to see if process 'n' has completed.

I.e. this would be like calling waitpid() with options=WNOHANG, instead of 0.

Why bother?

Well, sometimes in scripts (especially /etc/init.d/ scripts) it's useful to do 
something like:

timeout=30
interval=1

pppd ... updetach&
pid=$!

let -i n=0

while [ $n -lt $timeout ]; do
  wait -a $pid
  status=$?

  if [ $status -ne 128 ]; then break; fi

  sleep $interval
fi

if [ $status -ne 0 ]; then
  echo "Couldn't start PPPD or failed to connect.">&2
  exit 1
fi


as an example. (In this case, the original instance of pppd would have forked 
and detached when it successfully connected, causing the original instance to 
exit with 0; anything else would return non-zero.)

Does this seem like a reasonable enhancement?

Thanks,

-Philip




reply via email to

[Prev in Thread] Current Thread [Next in Thread]