I want to run a few commands, each of which doesn't quit until Ctrl-C is pressed. Is there something I can run to run all of them at once, and Ctrl-C will quit them all? They can share the terminal output.
Specifically, I have the compass compiler, coffeescript compiler, and a custom command that watches for file changes all running watching for file changes. I don't want to load up a terminal for each command.
I am suggesting a much simpler utility I just wrote. It's currently called par, but will be renamed soon to either parl or pll, haven't decided yet.
https://github.com/k-bx/par
API is as simple as:
Prefixing commands can be done via:
Use GNU Parallel:
To kill:
It can be done with simple Makefile:
Use
-j
option.Without
-j
option it executes in serial.You can also do dry run with `-n' option.
This bash script is for N parallel threads. Each argument is a command.
trap
will kill all subprocesses when SIGINT is catched.wait $PID_LIST
is waiting each process to complete. When all processes have completed, the program exits.Save this script as
parallel_commands
and make it executable.This is how to use this script:
Example:
Start 4 parallel sleep and waits until "sleep 4" finishes.
Based on comment of @alessandro-pezzato, to run multiples commands, just use
&
, between the commands.Example:
It's will run the commands in background.
To run multiple commands just add
&&
between two commands like this:command1 && command2
And if you want to run them in two different terminals then you do it like this:
This will open 2 terminals with
command1
andcommand2
executing in them.Hope this helps you.