Linux shell execution principle, linuxshell execution
Shell Introduction
Shell is a system user interface that provides an interface for users to interact with the kernel. It receives user-input commands and sends them to the kernel for execution.
Running background
A basic linux System Structure
B. It can be seen that shell is in an intermediate level in the system. It provides a solution for the interaction between users and kernel.
C. Many advantages of layered structure:
1. developers can only pay attention to one of the layers in the entire structure;
2. It is easy to replace the original implementation with the new implementation;
3. The dependency between layers can be reduced;
4. conducive to standardization;
5. facilitate the reuse of logic at each layer.
Disadvantages:
1. Reduced system performance.
2. Sometimes cascade modifications
Shell Command Execution Principle
The general practice of understanding the surface layer is to open the terminal, enter the command, press enter, and wait for the command to run. The result is displayed.
So what are the details of this process?
Open the terminal, enter the command, and press ENTER ---- IO interrupted
Waiting process:
Shell Analysis commands and parameters ---- shell (an interpreter at a terminal location)
Fork copies pcb-related resources nearby and prepares for command execution ---- system call
Exec executes the command in the fork sub-process.
After the execution is complete, return result ---- stack protection, stack frame Note: When the execution command such as ls &
& Symbol indicates that the command is executed in the background. When the command is executed, we cannot just enter the command because the parent process executes the shell command at fork, wait until the sub-process ends, unless the user actively Ctrl + C Stop command execution or Ctrl + z put into the background for execution.
Reference http://my.oschina.net/u/866271/blog/232840