Process Control (12)---system function

Source: Internet
Author: User

The system function is used to execute shell commands in the process. Note that the Exec family function can actually be used to execute shell commands in the process, but the two functions implement the shell command in a completely different principle.
    • The system function is equivalent to a procedure such as fork->exec->wait, which means that the system function calls the fork function to create a child process and then executes the shell command in the child process without affecting the execution of the parent process.
    • The direct use of the Exec family function to execute the shell command is to cover the code snippet and data segment of the shell command directly out of the original code snippet and data segment of the process, and the code in the original process will never be executed.
=======================================================The following is a source code for the implementation of the system function:from this code you can see the return values of the various system functions when they are in error:
    • When the passed-in parameter is NULL, 1 is returned
    • Returns 1 when the fork call fails
    • When the EXECL call fails, which means that the shell command cannot be executed, returns 127
    • Returns 1 when the Waitpid function is interrupted by a signal
    • Returns the state of the shell command itself exiting when the shell command is executed normally
 

Process Control (12)---system function

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.