"Vfork function" of Linux Learning

Source: Internet
Author: User

Why use Vfork ()?

You want the parent-child process to execute different code. For example:

In a network service program, the parent process waits for a service request from the client, and when the request is reached, the parent process calls fork, causing the child process to process the request, while the parent process continues to wait for the next service request to arrive. The vfork is the same as the function prototype for fork, which is used to create a new process, and the purpose of the new process is to exec a new program (execute an executable file). Since the new program will have its own address space, the Vfork function Don'tThe address space of the parent process Full Replicationinto the child process. Note the following two points:1. Child processes are called before exec or exitrun in the address space of the parent process。 The 2.vfork function guarantees that the child process executes first, The parent process may be scheduled to execute after calling exec or exit。 View code because in _exit (0), before the child process is running in the address space of the parent process, the + + operations on Glob and VAR are eventually output in the parent process. As for the final why use _exit instead of exit, see "The Linux Learning" Exit Function "why use Vfork ()?"

You want the parent-child process to execute different code. For example:

In a network service program, the parent process waits for a service request from the client, and when the request is reached, the parent process calls fork, causing the child process to process the request, while the parent process continues to wait for the next service request to arrive. The vfork is the same as the function prototype for fork, which is used to create a new process, and the purpose of the new process is to exec a new program (execute an executable file). Since the new program will have its own address space, the Vfork function Don'tThe address space of the parent process Full Replicationinto the child process. Note the following two points:1. Child processes are called before exec or exitrun in the address space of the parent process。 The 2.vfork function guarantees that the child process executes first, The parent process may be scheduled to execute after calling exec or exit。 View code because in _exit (0), before the child process is running in the address space of the parent process, the + + operations on Glob and VAR are eventually output in the parent process. As for the last reason to use _exit instead of exit, see "The Linux Learning" Exit Function "

"Vfork function" of Linux Learning

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.