Embedded Linux bare Metal Development (16)--shell implementation

Source: Internet
Author: User

Embedded Linux Bare Metal Development (16)--Shell implementation First, Shell Introduction

The shell is the interface between the user and the operating system and provides the user with an interface to use the operating system.

1. Graphical interface Shell

Graphical interface Shell (graphical User Interface shell is GUI shell)

most widely used graphical interface Shell is Windows Explorer (Microsoft's Windows Series operating system) and the Linux Shell, where Linux the shell includes X window Manager (Blackbox and Fluxbox), as well as the more powerful CDE, GNOME, KDE, XFCE.

2.command-line Shell

Command line Interface Shell (CLI shell)

Common Command-lineShell hasMS-DOSsystem,Windows PowerShell,Bourne Shell,Korn Shell,Bourne Again Shell,POSIX Shell,C Shell (including csh and tcsh).

Second, how Linux Shell works

The most important system program that Linux systems provide to users is the shell command language interpreter , Shell not part of the kernel, run in user mode outside the core , The basic function is to interpret and execute various commands that the user has entered, and to implement the interface between the user and the Linux core. After the initial start of the system, the core establishes a process for each end user to execute the shell interpreter. the Shell executes the following procedure:

1. reads the command line that the user entered by the keyboard.

2. Solution The command name as the file name and other parameters to the system call Execve function the form required for internal processing.

3. Terminal process Call Fork function Create a child process.

4. The terminal process itself uses the system call WAIT4 () to wait for the child process to complete (not wait if it is a background command). When the child process is run, call Execve, and the child process looks for the file in the directory based on the filename (that is, the command name) and calls it into memory to execute the program (explaining this command).

5. if there is a & (Background command symbol) at the end of the command, the terminal process does not have to wait for the system call WAIT4 (), immediately sends a prompt, lets the user enter the next command, go to the first 1 Steps . If there is no & at the end of the command, the terminal process waits until the child process (that is, the process running the command) finishes processing, reports to the parent process (the terminal process), and when the terminal process wakes up, after making the necessary discrimination, the terminal process prompts the user to enter a new command to repeat the process.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/82/A7/wKiom1deHTSiWAFZAABbvDpG6uo659.png "title=" Picture 1.png "alt=" Wkiom1dehtsiwafzaabbvdpg6uo659.png "/>

Program Framework:

While (1) {/* Repeat forever * /

  type_prompt (); / * Display prompt on the screen */

  Read_command (command,parameters); / * Read input from terminal * /

  if (fork ()!=0) { / * fork off child process * /

    /* Parent Code */

    waitpid ( -1,&status,0); /* Wait for child to exit * /

} else {

    /* Child code */

    Execve (command,parameters,0); / * Execute command * /

  }

}

Second, Shell implementations

Linux shell Implementation of a large number of calls to the Linux system API, GLIBC, etc., for the shell running on the smart210 board, need to remove the reliance on the Linux system, some of the functionality is implemented by porting and re-implementation, But the overall program framework is roughly the same. This project mainly implements a simple shell running on bare metal, there are two commands: LED, buzzer, the main function is to open/close an led by the accompanying parameters, turn on/off the buzzer.

Engineering source See accessories, can be burned in smart210 run.

Reference blog:

Shell Basic working principle ( CSDN yjz0065 )

teach you to write a shell with basic functionality (Blog Park Five Mountains )


This article from "Endless life, Struggle not only" blog, please be sure to keep this source http://9291927.blog.51cto.com/9281927/1788552

Embedded Linux bare Metal Development (16)--shell implementation

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.