The difference between source/fork/exec in the shell

Source: Internet
Author: User

Tag: exec source Fork

Fork is a system call to Linux that creates a child process that is a copy of the parent process, obtains a certain resource allocation from the parent process, and inherits the environment of the parent process. The only difference between a child process and the parent process is the PID (process ID). Environment variables (variables passed to child processes, hereditary is the fundamental difference between local variables and environment variables) can only be passed from the parent process to the child process in one direction. Regardless of how the environment variable of the child process changes, the environment variables of the parent process are not affected. The commands in the default shell are this way, create Sub-shell, and then execute. After execution, return to the parent shell.

Both exec and source are part of Bash's built-in commands, and no new processes are generated during the execution of source and exec, and the script being invoked executes within the same shell process as the parent script. The difference between source and exec is that after exec invokes a new script, the content after the Exec line in the parent script is no longer executed. So the variables and environment variables declared in the invoked script can be obtained and used in the main script.


Summarize:

SOURCE command: Do not create child processes, execute scripts in the current shell process,
EXEC command: Do not create a child process, execute script in the current shell process, the content after the Exec line in the parent script does not execute

Fork is a system call, a child process is created, the parent process blocks waiting for the child process to finish executing, and then continues to execute

The difference between source/fork/exec in the shell

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.