Chapter III Study Notes

Source: Internet
Author: User

First, the process

1. The process is a procedure for the implementation period

2. Execution thread, short thread, is the object that is active in the process

3. Process provides two virtual mechanisms: virtual processors and virtual memory

Ii. process descriptors and task structures

1. The kernel stores the list of processes in a two-way circular chain List of the Jiaozuo task queue, each of which is a structure of type task_struct, called the process descriptor

2. Allocation and storage of process descriptors:

(1) Purpose: Linux allocates task_struct structure through slab to achieve object reuse and cache coloring (to avoid resource consumption from dynamic allocation and release of resources)

(2) Allocation: The end of the stack for each task (for example, for an upward-growing stack, which is at the top of the stack) has a struct thread_info, which points to the TASK_STRUCT structure

(3) Find:

1) Most of the code in the kernel processing process is done through task_struct, so you need to find the process descriptor for the currently running process through the current macro

2) in the X86 system, current Thread_info the back of the stack pointer to the first 13 significant bits to calculate the offset (via Current_thread_info function)

3. Process status

The process must be in one of five states at any time.

(1) task_running

(2) Task_interrupt

(3) Task_uninterrupt

(4) task_traced

(5) task_stopped

4. Set the current status of the process

(1) Call the Set_task_state (task,state) function to set the process to the specified state

5. Process context

(1) Executable code is loaded from an executable file into the address space of the process execution. When a program executes a system call, the kernel "executes on behalf of the process" and is in the context of the process

(2) Contrast: In the context of interrupts, the system does not represent process execution-there is no process to interfere with these interrupt handlers

Third, process creation

How the process of 1.Unix systems is created

(1) fork () creates a child process by copying the current process

(2) Exec () is responsible for reading the executable file and loading it into the address space to start running

(3) copy at time of writing

1) Linux fork () uses write-time copies to postpone or even dispense copies. The kernel does not replicate the entire address space when it creates a new process, but rather allows the parent process and child processes to share the same copy, until the child process/parent process needs to write it.

2) Thus, the actual cost of the fork is simply to copy the page table of the parent process and create a unique process descriptor for the child process

2.fork function

(1) Linux with clone system call to implement fork

(2) from clone to call Do_fork ()

(3) define Do_fork () in <kernel/fork.c> to complete most of the work in the creation, it calls the Copy_process function, and then lets the process start running

Iv. Kernel threads

1. Kernel thread: A standard process that runs independently in kernel space.

2. Kernel threads do not have separate address space , only run in kernel space , never switch to user space, can be dispatched and preempted .

3. Kernel threads can only be created by other kernel threads

v. the end of the process

1. At the end of the process, the kernel must release the resources it occupies and inform the parent process.

2. The reason for the end of the process: typically comes from itself, when called by the exit () system call.

3. Delete the process descriptor

by Release_task (), the process descriptor is deleted, and all resources are released.

4. Resolving the Orphan process

(1) The parent process exits before the process, leaving the child process, the orphan process

(2) Workaround: In the current thread group to the orphan process to find a new parent process;

Directly with Init as its parent process

Chapter III Study Notes

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.