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 exit,
run 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 exit,
run 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