Multi-process programming, Wang Ming Learning Learn

Source: Internet
Author: User
Tags function prototype ming

Multi-process programming

First, function learning

1.1 Creating a Process fork

1.1.1 Function prototype

pid_t fork (void);

1.1.2 Function function

Create a child process

1.1.3 Owning header file

<unistd.h>

1.1.4 return value

Success: The parent process returned a successfully created child process PID subprocess returned 0

Failed: Parent Process returned

1.1.5 parameter Description

No

1.2 Creating a process vfork

1.2.1 Function prototype

pid_t vfork ();

1.2.2 Function function

Create a child process and block the parent process

1.2.3 Owning header file

<sys/types.h> <unistd.h>

1.2.4 return value

Success: The parent process returned a successfully created child process PID subprocess returned 0

Failed: Parent process returned-1

1.2.5 Parameter Description

No

Fork and vfork Contrast:

Both fork and vfork can be used to create child processes, but there are also the following differences:

1. Fork: The child process has separate data segments, stacks. Vfork: The child process shares the data segment with the parent process, the stack.

2. Fork: The order of execution of the parent and child processes is indeterminate vfork: Child processes run first, run after the parent process

1.3 Process waiting wait

1.3.1 Function prototype

pid_t Wait (int* status);

1.3.2 Function function

Suspends the process that invokes it until its child process ends

1.3.3 Owning header file

<sys/types.h> <sys/wait.h>

1.3.4 return value

Success: Returns the end of the child process ID

Failed:-1

1.3.5 parameter Description

Status: Record child process exit status

1.4 Execution Program function name execl

1.4.1 Function prototype

int execl (const char* pathname,const char*arg,...)

1.4.2 function function

Run an executable file

1.4.3 Owning header file

<unsitd.h>

1.4.4 return value

Success: Do not return

Failed: Return

1.4.5 parameter Description

Pathname: The path to the executable file to run

ARG: The parameters required to run the executable file

1.5 terminating the process Exit equals _exit

1.5.1 function prototype

void _exit (int status)

1.5.2 function function

Terminates the process being called

1.5.3 Owning header file

<unistd.h>

1.5.4 return value

No

1.5.5 parameter Description

Status is used as a city exit status returned to the parent process

Parent Process exit: can be return 0 and exit

Child process exit: only exit

Multi-process programming, Wang Ming Learning Learn

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.