[Top][All Lists]

[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: 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:


pppd ... updetach&

let -i n=0

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

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

  sleep $interval

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

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?



reply via email to

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