I want to run several commands in parallel, but I have no idea why the following code piece does not work.

( ping )
( ping )

It completely ignores the second ping command. Why is that so?

Edit: OK, now I know that you can run them in parallel by doing &.

ping & ping

But why did the above code piece not work?

  • 1
    the first ping doesn't end by itself, so the 2nd command won't run until you kill the first ping... – Jeff Schaller Mar 5 '16 at 13:01

A subshell is not forking by default and you also would have to use & to send it to the background to execute the second subshell without waiting for the first subshell to end.


ping & ping
  • In most shells, a subshell forks and in any case, subshell or not, the shell will fork a process to execute that ping command in a separate process as there's no shell that I know that has ping as a builtin command. But the point here is that the shell will wait for the termination of that process. & doesn't make a difference whether the shell forks or not (it forks with and without &) but whether the shell will wait or not for that process to finish before carrying on with the rest of the script. – Stéphane Chazelas Sep 3 '18 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.