Environment:
Operating system: ArchLinux; Terminal Simulator: Rxvt-unicode (URXVT); Shell:bash;
The background process referred to here is a ampersand (&) behind the command line, and the foreground process is the form of a command line that does not add ampersand to the background process.
1. When we turn on URXVT, the terminal emulator launches bash as its own subprocess, and bash displays a command prompt in URXVT to wait for the user's input.
2. After we enter the command, Bash is responsible for interpreting the command.
3. When bash finds the corresponding command (without studying the bash's source code and does not know what to do if it is not found), Bash performs a fork and the child process is responsible for executing the user input commands.
4. If a foreground process, the parent process will wait for the child process to end; If a background process, the parent process does not wait, so that the parent process can continue to get the user's input.
5. For background processes, the data can still be read and written from the current terminal (the background process executed in this terminal), which is the standard input and standard output of the background process.
The program verifies that the current terminal is still the standard output of the background process, but does not yet know how to verify that the current terminal is the standard input for the background process.
6. If the background process ends before entering enter next time, it will print its exit status the next time you enter enter.
7. The foreground process has a higher priority than the background process.
Still feel not very clear, because did not understand thoroughly.
Talk about the background process and foreground process of shell in Linux