for i in 1 2 3 4; do while : ; do : ; done & done stop for i in 1 2 3 4; do kill %$i; done
Here is what the above code is Doing:
1. It starts 4 background jobs.
2. It waits for all of them to finish.
3. It kills all of them.
The problem is that the kill command is not working.
The reason is that the kill command is not being run in the same shell as the background jobs.
The solution is to use the wait builtin command.
The wait builtin command waits for all background jobs to finish.