4 ms·
You guys know that in bash you can use `&` to pass a foreground terminal process to the background and then use `wait` to wait for all the session's background
by cusspvz 3y ago
You guys know that in bash you can use `&` to pass a foreground terminal process to the background and then use `wait` to wait for all the session's background process to end, right?
- oniony 3y agoI've been using `&` to run stuff in the background for donkeys, but had no idea about `wait`.
- bduffany 3y agoYes, and those work well for smaller workloads, but if you just run 1,000,000 commands with `&` in a `for` loop, it will grind your computer to a halt (if the tasks are modestly resource intensive). GNU parallel will let you run those same 1,000,000 tasks but make sure that only (e.g.) 16 of them are running at once. It's not easy to do that in bash.
- Alifatisk 3y agoDidn’t know about wait
- seized 3y agoAnd that's not really at all comparable to what Parallel can do.... Bash can't do that across thousands of cores on separate machines for example.
- remram 3y agoStrong "Dropbox is just rsync it'll never sell" vibes.
- da-x 3y agoIt takes time to notice that if you do _several_ of these background jobs with `&`, you will only get the exit status of the last one when you do `wait`. Errors of the others will be swallowed. Then you _have_ resort to 'wait <pid>' with the 20 lines of bash coded need to manage all those PIDs. I have a large editor bash snippet just for that.