4 ms·
using sh is usually preferred: somecmd & someothercmd & wait runs the two commands in parallel and waits for both. no need for await. to run in serial repl
by rurban 5y ago
using sh is usually preferred:
somecmd & someothercmd & wait
runs the two commands in parallel and waits for both. no need for await. to run in serial replace & with && and skip the wait
- tgsovlerkhgsel 5y agoHuh, neat, didn't know "wait". Thanks! Still doesn't let you easily get the output of the two commands, but a good start.
- 10000truths 5y agoYou can just use files as a temporary buffer: (/my/bg_producer1 > /shm/file1) & (/my/bg_producer2 > /shm/file2) & /my/longrunningfgjob wait (/my/consumer1 < /shm/file1) & (/my/consumer2 < /shm/file2) & wait
- striking 5y agoYou lose the ability to know whether they succeeded or failed, though. Like most things given to you for free by the shell in shell scripting, it's only like halfway to a real solution. (If you know how many subshells you started and won't get confused by which is which, you can use `wait -n && wait -n && ...` in bash)
- MisterTea 5y agoCouldn't you redirect the stdout/error file descriptors to achieve the same thing?