The most important system program provided by Linux to users is the Shell command language interpreter. It does not belong to the kernel, but runs in user mode outside the core. Its basic function is to explain and execute various commands that users enter to implement interfaces between users and Linux core. After the system starts, the core creates a process for each end user to execute the Shell interpreter. The execution process is basically as follows: (1) read the command line entered by the user on the keyboard. (2
Basic working principle of Shell
The most important system program provided by Linux is the Shell command language interpreter. It does not belong to the kernel, but runs in user mode outside the core. Its basic function is to explain and execute various commands that users enter to implement interfaces between users and Linux core. After the system starts, the core creates a process for each end user to execute the Shell interpreter. The execution process is basically as follows:
(1) read the command line input by the user's keyboard.
(2) analyze the command, use the command name as the file name, and transform other parameters into the form required by the system to call the internal processing of execve.
(3) The Terminal Process calls fork () to create a sub-process.
(4) The Terminal Process itself uses the system to call wait4 () to wait for the completion of the sub-process (if it is a background command, it does not wait ). When a sub-process calls execve () when it is running, the sub-process searches for the relevant file in the directory based on the file name (that is, the command name) and transfers it to the memory, execute this program (explain this command ).
(5) if the end of the command has a "&" (background command symbol), the terminal process does not need to call wait4 () to wait, and immediately sends a prompt, asking the user to enter the next command and convert it to "(1. If no & sign exists at the end of the command, the terminal process will wait until the sub-process (that is, the process that runs the command) completes the processing and then terminate the process. report it to the parent process (Terminal Process, at this time, the terminal process wakes up and after necessary identification, the terminal process sends a prompt asking the user to enter a new command and repeat the above process.
Shell basic execution process and the relationship between parent and child processes.