The process of creating a new process for the Linux kernel

Source: Internet
Author: User

The process of creating a new process for the Linux kernel

20135224 Chen Shi + original works reproduced please specify the source + "Linux kernel analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000

Brief introduction:

PCB definition: The various execution and data information headers required by the process

Task_struct: A data structure that is roughly:

State,scheduling information,identifiers,ipc:inter_process COMMUNICATION,SMP and so on.

The first part

Analyze the kernel processing process:

Fork (), calling the general function of the process.

long do_fork(unsigned long clone_flags关键部分:
   { p = copy_process(clone_flags, stack_start, stack_size,
             child_tidptr, NULL, trace);}

Copy_process (), initialization of various resources.

p = dup_task_struct(current):Call Dup_task_struct () to create a kernel stack for the new process

if (retval)Statement Group, copying parts of a shared process

Dup_task_struct ():

tsk = alloc_task_struct_node(node)Open up memory for task_struct

ti = alloc_thread_info_node(tsk, node)Ti points to the first address of the Thread_info, and also the first address of two consecutive pages that the system assigns to the new process.

err = arch_dup_task_struct(tsk, orig)Copy the task_struct information of the parent process into the new task_structtsk->stack = ti;

setup_thread_stack(tsk, orig)Initialize the thread info structure

set_task_stack_end_magic(tsk)End of stack address set data is stack end indicator (for overflow detection)

第二部分

GDB Trace Sys_clone:

Open With GDB

Set Breakpoints with B

Breakpoints are set clone,fork,process,ret_from_fork and other key sub-functions

P-value in thread

Summarize

The operating system creates a new process by replicating the parent process by calling Do_fork to implement----each newly created process dynamically assigns a task_struct structure

In order to organize all the processes in the kernel, Linux provides several organizational ways, in which the hash table and the two-way loop list are for all processes in the system (including kernel threads), while the run queue and wait queue are organized by the process in the same state

The process of creating a new process for the Linux kernel

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.