Exec and source parsing in Shell

Source: Internet
Author: User
Exec and source in Shell parse both exec and source are bash internal commands. before talking about these two commands, let's talk about the concept of fork: fork is a linux system call, used to create a child process ). A child process is a copy of the parent process ,... exec and source in Shell parse both exec and source are bash internal commands. before talking about these two commands, let's talk about the concept of fork: fork is a linux system call, used to create a child process ). A child process is a copy of the parent process. it obtains a certain amount of resource allocation from the parent process and inherits the environment of the parent process. The unique difference between a child process and a parent process lies in the pid (process id ). Environment variables can only be transmitted from the parent process to the child process in one way. they do not affect the environment variables of the parent process. Run the www.2cto.com script: 1. generate a new shell and then execute scripts, that is, the common sh command. Generally, there is the following line at the beginning of the scripts File :#! /Bin/sh2. run the command in the current shell. other shells are no longer enabled. Source Command: no new shell (process) is generated, but all commands are executed in the current shell. Exec command: no new shell (process) is generated, but the current shell process is closed during execution, and the subsequent commands are switched to continue to be executed. Www.2cto.com exec: 1. the system calls exec to replace the original process with a new process, but the process PID remains unchanged. Therefore, the exec system call does not create a new process, but replaces the content of the original process context. The code segment, data segment, and stack segment of the original process are replaced by the new process. 2. exec is a function cluster consisting of six functions with excl and execv headers respectively. 3. What is the difference between exec and system? 1) exec directly replaces the original program with a new process and does not return to the original program after running. 2) system is to call shell to execute your command. system = fork + exec + waitpid. after the execution is complete, return to the original program. Continue to the following part. That is to say, if you use exec to call, you should first fork a new process, and then exec. while system does not need to fork a new process, it has been encapsulated.
 

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.