Linux application Development-multi-process programming

Source: Internet
Author: User

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

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.