Operations performed by calling the fork () function

Source: Internet
Author: User

The only way to create a process is to use the system call fork. The core is to complete the fork system call in several steps:
1: assign a table item to the new process. The number of processes that a user can run at the same time is limited. This limit is not imposed on Super Users, but it cannot exceed the maximum number of table items in the table.
2: Give the sub-process a unique process identifier PID. The process identifier is actually the index number of the table item in the progress table.
3: copy the table entry of a parent process to the child process. The process entry of the core initialization sub-process is copied from the parent process. Therefore, sub-processes have the same uid, EUID, GID, nice value used for priority calculation, current directory, current root, user file descriptor table, and so on as the parent process.

4: add the reference numbers of files connected to the parent process and the index node table. 1. These files are automatically connected to the child process.

5: the core is to create a user-level context for the child process. The core is to allocate memory for the U zone, zone, and auxiliary page table of the child process, and copy the content of the parent process zone. This generates the static part of the process;

6: generate the dynamic part of the process. The core copies the first layer of the context of the parent process, that is, the register context and core stack. The core then virtual a context layer for the child process, this is to enable the sub-process to "Restore" its context. At this time, the call will return the child process PID to the parent process, and the child process will return 0.

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.