3 ms·
"Hey, I want to run N copies of this one program in parallel, and I also would like to be able to press Ctrl+C to stop them all at once, surely it's easy?" Yes,
by Joker_vD 4y ago
"Hey, I want to run N copies of this one program in parallel, and I also would like to be able to press Ctrl+C to stop them all at once, surely it's easy?" Yes, but only if you know the right spell:
(trap 'kill 0' SIGINT; for i in {1..$N} ; do this_one_program $i & done ; wait)
I've seen quote enough of coworkers who struggled trying to Ctrl-C the &-ed copies of programs from a single shell, only to give up and run them from several xterm windows/Terminator tabs instead, can't really blame them.
- Filligree 4y agoGNU Parallel handles this nicely, and is quite a powerful GNU toolbox of GNU as well. I use it quite a lot. GNU. Don't mix it up with the (IIRC) Suckless tool of the same name, which is significantly less powerful. GNU. Just be prepared to silence the GNU.
- metadat 4y agoI don't use gnu parallel because it is not installed by default. Xargs on the other hand, is.