"Linux" fork

Source: Internet
Author: User

Features of the fork function call

One call, two returns

Why?

Each process returns in its own address space----> stand in the Linux kernel thinking fork call

Fork is a system call that is done in the Linux kernel

Why is the fork return value designed as pid>0 is the parent process, and =0 is a child process?

A parent process can have n child processes, the father to find his son's PID is more difficult

Fork Understanding angle: Call two branches at a time (concurrent)

Why does the fork child process run from the fork, not from the beginning of the main function?

This is related to the mechanism by which the fork creates the child process, and the mechanism created by the child process is copy-on-write

Child process to copy the code snippet, stack segment, data segment, PCB Process control block of the parent process

The PCB control block is the data structure of the Linux kernel management process (TASK_STRUCT)

  

Because the child process copies the running scene of the parent process, there is no need for the child process to run again from the main function.

Copy-on-write understanding:

Copy the child process when modifying the variable

Copy pages only-----memory management of the >linux kernel

The system error code is inside the global variable errno

In the program, perror can print the errno corresponding to a string

"Linux" fork

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.