Use fork () to create a child process under Linux and cause the parent process to wait for the child process to end

Source: Internet
Author: User
int status;pid_t t = fork (), if (t) {waitpid (T, &status, 0);}    else{System ("VI temp.txt"); Exit (0);} After both the parent and child processes have finished executing the parsing process: if and else or select branch.
The main reason is that thefork () function is called once and returned two times . The difference of two returns is that the return value of the child process is 0, and the parent process returns the process ID of the new child process. When returned, the parent process executes waitpid (t, &status, 0) waiting for the child process to end, and the child process enters another branch to execute system ("VI temp.txt"); exit (0); This code can be described as the parent process and the child process have performed a single judgment.

Use fork () to create a child process under Linux and cause the parent process to wait for the child process to end

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.