Best way to use dhcpc / avahi without delaying other init scripts ?

Harald Becker ralda at gmx.de
Tue Apr 30 18:52:12 UTC 2013


Hi Avery !

>Maybe you just want to background the whole chunk of logic using an sh
>block?
>
>(
>   dhcpc -b ...
>   ...if it failed to get an address from dhcp, do something else...
>) &

You are right, but using braces instead of parenthesis may avoid an
extra fork (saves some time/resources).

{
  ... your logic goes here
} &

In addition it is good practice to remember the pid of the background
job, so you are able to wait for completion when it's required.

{
  ... your dhcp logic
} & dhcp_pid=$!

... 

# when you need to wait for dhcp initialization
wait $dhcp_pid
... and here you may test result code ($?) of your dhcp logic block

--
Harald


More information about the busybox mailing list