Hacker News new | ask | show | jobs
by cusspvz 1029 days 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?
6 comments

Yes, 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.
I've been using `&` to run stuff in the background for donkeys, but had no idea about `wait`.
And 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.
It 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.

Strong "Dropbox is just rsync it'll never sell" vibes.
Didn’t know about wait