Description of the process and creation of the process-sixth week (20135304 Liu Xipeng)

Source: Internet
Author: User

Description of the process and creation of the process

Liu Xipeng 20135304

"Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000

First, description of the process

1, 1 Process descriptor Task_struck data structure (i)

(1) The three main functions of the operating system: process management, memory management, file system.

(2)

Process Control block Pcb--task_struck

Tty_struck Console

Description of the Fs_struck file system

Files_struck Open File Descriptor

Description of Mm_struck Memory

Description of the Signal_struck signal

(3) State of the operating system principle: ready state, operating state, blocking state

(4)

Process status in kernel management:

Task_tunning (can run) Get CPU control is running, is dispatched out is ready state.

Task_zombie (Process aborted)

Task_interruotibie (blocking state)

Task_uninterruotibie (blocking state)

(5) Identifier of the process: PID (used to identify the process)

1, 2 process descriptor Task_struck data structure (ii)

(1) State operation status (Specify process state)

(2) SMP conditional compilation (multi-processor will be used)

(3)

struct List_head The list of tasks processes, two-way loop linked list, linked list can be operated independently

(4) Each process has its own independent address space, and 32-bit x86 has a 4G process address space.

(5) pid_t PID identifies a process

(6)

Parent-child relationship of a process: the relationship between siblings is connected by a doubly linked list.

(7) CPU-related status: Thread_struct (SP, IP) process context switch period key role

(8) struct Files_struct*files Open file list

(9) struck signal_struct *signal signal processing related work

Second, Process Creation Process

2, 1 process creation overview and fork a process user-state code

(1) (File system, signal, memory) The process descriptor has a corresponding pointer to its contents, for research.

(2)

How the process was created: Copy a process descriptor, NO. 0 process with code to die, process 1th copy No. 0 process PCB, according to process 1th need to modify the PID, and finally add an init executable program.

(3)

Where does the child process start executing: How does the shell command line create a child process?

Fork () User state to create child process

Fork system call returns once for each parent process and child process

(4) Fork in child process the return value is the ID of the parent process

2, 2 Understanding the process of creating complex code methods

(1) System call review:

The int0x80 is an interrupt instruction that transforms the user-state stack into a kernel-state stack and saves the CPU's most critical field EIP and ESP to the kernel stack.

(2)

Where the child process begins execution: fork () out of the child process begins to return in the kernel. Create a framework for a process: Copy a process descriptor, NO. 0 process with code to die, process 1th copy No. 0 process PCB, according to process 1th need to modify the PID, and finally add an init executable program.

(3) What to do during the creation process: Modify the PCB, set up the list, modify the allocation kernel stack, save the location where the process executes, save the SP, IP (avoid confusion), need to have the thread to set the EIP and ESP location.

2, 3 The key methods related to the process of creating the browsing process

(1)

To create a new process that executes in the kernel:

Copy a pcb--task_struct

Assigning a new kernel stack to a new process

Change the copied process data, such as PID, process chain list, etc.

(2) System call kernel processing function: Sys_fork, Sys_clone, sys_vfork

(3) The copy process contained in Do_fork () creates the main code for the content of a process

(4) Arch dup_task_struct copy the entire PCB (the value of the *dst=src* data structure is copied to DST)

(5) Thread_info kernel stack, create a page, larger (allocate kernel stack space)

(6) P Pointer to a child process descriptor

(7) Copy_thread from the PID of the child process to find the address of the stack, the SP assigned to the past, the parent process to copy the bottom of the stack, including the stack top data, thread IP content.

2, 4 where does the new process start?

(1) Where the child process starts: ret_from_fork

(2)

The int instruction and save_all the contents of the kernel stack.

(3) The Syscall_exit kernel stack in ret_from_fork returns to the user state (process space of the child process) normally.

2, 5 using GDB to track the process of creating a new process

Your own experiment:

(1) Delete the menu, clone a new one, cover the TEST_FORK.C, compile the kernel, you can see the fork command

(2) Set breakpoint Sys_clone, set breakpoint Do_fork, set breakpoint Dup_task_struck, set breakpoint copy_process, set breakpoint Copy_thread, set breakpoint Ret_from_fork

(3) Fork in Menuos, you will find that the fork function is parked in the parent process

(4) After the continuation of the execution, stopped in the do_fork position

(5) Press S to enter the function, you can see DST = src (that is, the struct that replicates the parent process)

(6) Press N to continue tracking

(7) In Copy_thread, you can see that the Task_pg_regs (p) is the kernel stack-specific address found and initialized

Description of the process and creation of the process-sixth week (20135304 Liu Xipeng)

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.