educative.io

Educative

In the example, how did all 4 programs run simultaneously

We used four commands separated by & and I always understood that second program would only run after first one has completed successfully. Since the program is infinite loop, how did all four programs separated by & ran at once ?

Hello @Abhishek_Vaid,

There is a difference between & and &&. When we chain commands using &, all the commands will run simultaneously. However, when we chain commands using &&, the commands will execute one by one. Each command will wait for the previous command to execute. To experiment this, try executing ls & pwd & date and ls && pwd && date

Hope this helps!