Copy_process () function

Source: Internet
Author: User

The work completed by the copy_process () function is very interesting:
. Call dup_task_struct () to create a kernel stack, thread_info structure, and task_struct for the new process. These values are the same as those of the current process. In this case, the descriptor of the child process and the parent process is identical.
After checking the newly created sub-process, the number of processes owned by the current user does not exceed the resource limit allocated to him.
. Now, the child process starts to distinguish itself from the parent process. Many members in the process descriptor must be cleared by 0 or set as the initial value. The value of a process descriptor is not inherited, but mainly statistical information. Most data in the process descriptor is shared.
. Then, the sub-process status is set to task_uninterruptible to ensure that it will not be put into operation.
. Copy_process () calls copy_flag () to update the flags member of task_struct. The pf_superpriv flag indicating whether the process has superuser permissions is cleared. The pf_forknoexec flag indicating that the process has not called the exec () function is set.
. Call get_pid () to obtain a valid PID for the new process.
According to the parameter flag passed to clone (), copy_process copies or shares opened files, file system information, signal processing functions, process address spaces and namespaces. In general, these resources will be shared by all threads of the given process; otherwise, these resources are different for each process and therefore copied here.
. Finally, copy_process () is used to scan the tail and returns a pointer to the child process.
Return to the do_fork () function. If the copy_process () function is returned successfully, the newly created sub-process is awakened and put into operation. The kernel intentionally selects sub-process execution. Therefore, generally, sub-processes call the exec () function immediately to avoid additional overhead of copy during write. If the parent process is executed first, it may start to write data to the address space.

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.