Talk about the background process and foreground process of shell in Linux

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.