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