Multi-ProcessingOne big difference between a computer and a brain is that the computer is much better at executing multiple programs simultaneously. If a computer has multiple processors, each processor can execute a different program. Or the computer can use "time-slicing" to switch one processor between different programs, which may also be called "tasks" or "jobs". While some people may good at multi-tasking a few different activities, computers can easily execute hundreds of different tasks at the same time, without getting confused or schizophrenic. Different processes can interact by accessing the same files or by access the same memory locations. Special care needs to be taken when running multiple processes that interact with each other, as the order in which actions are taken by the different processes is not always predictable.
Foreground Processes - Background ProcessesOne way to run multiple processes at the same time is put them in the "background" as you start them from a command line (shell window). When you start a process (task) in the background, the shell doesn't wait for that process to finish before returning to interactive mode and accepting additional commands. Besides the memory limitations of your system, there are no limits on the number of background commands you can enter. In order to run a command as a background process you type a space and an ampersand after the command. For example:
$ command1 &
Unlike background jobs, foreground processes may present an interactive graphical user interface, and you have to wait for a foreground process to finish before you can start another process from the same shell. To start a foreground process, enter a command at the prompt followed by a return. For example:
$ cat file1
Processes versus ThreadsModern programming languages allow the software developers to specify parallel execution of code. This is frequently done in order to take advantage of computer architectures with multiple processors (CPUs) or cores. Sometimes processors are called "cores" if they are associated with other processors in an particular architecture that optimizes their performance. In that case a CPU is said to contain multiple cores.
In general there is no fixed relationship between a (Linux) process and a processor. The operating system assigns a process to a random processor and may switch the processor for that process at any time. Threads are a mechanism for a programmer to specify separate processes from within a program. The operating system will try to associate each thread/process with a separate processor. If there are more threads/processes than processors/cores, some processors/cores may execute multiple threads/processes by switching between them.