Hi Avery !
>The & sign implies the need for a fork anyway.
One fork yes, this is the required fork, but ...
> As far as I know, all modern shells are smart enough to avoid
> double-forking in this case.
Modern shells? You mean like bash? Yes! ... but I'm not sure if Busybox
ash knows about that optimization.
That is ( ... ) forks a subshell with the main shell immediately waiting
until subshell has finished. ( ... ) & forks into background, than
forks again in background to run a subshell. { ... } & forks once to
run the group of commands in the forked shell.
To verify: Use GNU /bin/ps --forest in the examples above. (...)& gives
three shell processes, where {...}& shall only give two shell
processes. Test with bash and Busybox ash and see difference. I did
this with older Busybox versions, but don't think anybody improved
subshell forking in ash.
>:)
Nice to have optimizations, but better to know how to optimize for all
shells, not only modern ones. Small change, big performance hit.
--
Harald
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox