Linux Application Development-multi-process programming
One creation process
The difference between fork and vfork
1 Fork creates a child process that has its own data segment and stack and vfork creates a child process that shares the data segment with the parent process
Two-process exit
The parent process can use return 0 and exit (0) and the child process can only use Exit (0)
The difference between three execl and fork
EXECL does not create a child process, but overwrites the following code snippet
Fork to create child processes without overwriting code snippets
Four corresponding functions
1 Creating a process
function name Fork
Function prototype pid_t fork (void)
function function to create a child process
Owning header file #include <unistd.h>
The return value succeeds in returning the PID of the child process that was created in the parent process, returning 0 in the child process
Failed return-1
Parameter Description None
2 Creating a process
Function name Vfork
Function prototype pid_t vfork (void)
function function to create a child process that blocks the parent process
Owning header file #include <sys/types.h> #include <unistd.h>
return value
The PID of the child process is returned successfully in the parent process, and 0 is returned in the child process
Failed return-1
Parameter description
No parameters
3 Process Wait
Name of function
Wait
Function prototype
pid_t Wait (int *status)
function function
Suspends the process that invokes it until the child process accepts
Owning header file
#include <sys/tyeps.h>
#include <sys/wait.h>
return value
PID for successfully returning the terminated process
Failed return-1
Parameter description
Record the exit status of a child process
4 Execution procedures
Name of function
Execl
Function prototype
int execl (const char *pathname, const char *arg, ...)
function function
Run the executable file
Owning header file
#include <unistd.h>
return value
Success does not return
Failed return-1
Parameter description
Pathname Path to executable file
Arg typically runs the required parameters for an executable file, and null is not used.
Linux application Development-multi-process programming