I have two programs that run indefinitely. I know I can fork one to the background then run the other by typing this at the command line:
> program1 &
> program2 &
However, I'm lazy and don't want to hit enter, I just want to run them both immediately. But bash complains when I do this:
> program1 &; program2 &
How can I run them both at the same time?
An ampersand does the same thing as a semicolon or newline in that it indicates the end of a command, but it causes Bash to execute the command asynchronously. That means Bash will run it in the background and run the next command immediately after, without waiting for the former to end.
To send a running command in the background: If users have already started a certain command and while they were using their system, their command-line blocks up, then they can suspend the execution of their currently foregrounded process by using “ctrl+z” for windows and “command+z” for mac systems.
To run script in parallel in bash, you must send individual scripts to background. So the loop will not wait for the last process to exit and will immediately process all the scripts.
You leave out the ';' char, i.e.
program1 & program2 &
I hope this helps.
try
(program1 &) ; (program2 &)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With