I'm a bit confused about concurrency and parallelism in the bash shell. As I understand it, when we run commands in more than one subshells at the same time, these commands run in parallel on individual processor cores.
For example;
cmd1 & cmd2 & cmd3 &
Here, the "ampersand" sign is run in the background (aka the subshells) of each command at the same time.It could be create in subshells in other ways. (Like writing in parentheses or using a pipe ..).
In this direction, the questions I wonder the answers of;
- Bash provides parallelism through subshells, other hand is concurrency also achieved using another method on bash? As far as I know, concurrency works in a way that a single CPU executes operations intermittently. Do I need to implement a method externally to achieve this, or is bash already working this way (concurrency ) anyway.
- If I occupy all CPU cores using parallelism, will the system crash or is there a protection mechanism against this situation?
- What is the difference between the parallel I provide with subshells and the GNU Parallel tool? If the GNU Parallel tool works better, how does it achieve this?
- Which of the "Parallel" or "Concurrency" operations works more efficiently?
- What kind of losses are experienced when making "parallel" or "concurrency" operation, unlike normal (sequential execution of commands)?
foo &
does mean “runfoo
in the background”. I don't know what you think “in the background” means, but that term is used in the manual of most shells, as well as in the POSIX specification, to describe the behavior of&
.