Implement a simple interactive Shell using various C functions

Source: Internet
Author: User
Use a variety of C functions to implement a simple interactive Shell-General Linux technology-Linux programming and kernel information. The following is a detailed description. The following requirements apply to the implementation of a simple interactive Shell using various C functions:

1. give a prompt, ask the user to enter a line of command, identify the program name and parameters, and call the appropriate exec function execution program. after the execution is complete, give the prompt again.

2. identify and process the following symbols:

• Simple standard input/output redirection ( <And> ): In the example 30.5 "wrapper", dup2 is used and exec is used.

• Pipeline (|): The Shell process first calls pipe to create a pair of pipeline descriptors, and then fork generates two sub-processes. one sub-process closes the read end and calls dup2 to assign the write end to the standard output, another sub-process closes the write end and calls dup2 to assign the read end to the standard input. The two sub-processes respectively call the exec execution program, while the Shell process closes both ends of the pipeline, call wait and wait for the two sub-processes to terminate.

Your program should be able to process the following commands:

○ Ls △- l △- R ○> ○ file1 ○
○ Cat ○ <○ file1 ○ | ○ wc △- c ○> ○ file1 ○
○ Represents zero or multiple spaces, and △ represents one or more spaces

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.