top | item 37208934

(no title)

cusspvz | 2 years 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?

discuss

order

bduffany|2 years ago

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.

oniony|2 years ago

I've been using `&` to run stuff in the background for donkeys, but had no idea about `wait`.

seized|2 years ago

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.

da-x|2 years ago

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.

remram|2 years ago

Strong "Dropbox is just rsync it'll never sell" vibes.

Alifatisk|2 years ago

Didn’t know about wait