Linux principle: Process

Source: Internet
Author: User
Linux principles: processes-general Linux technology-Linux programming and kernel information. For more information, see the following section. I plan to learn the Linux principles from a simple perspective. from the top down, I will first understand the principles and then go into depth one by one. First, let's take a look at the Linux Process.

I. Linux Process Context

Linux Process context is a collection of process composition elements. Including process descriptor tast_struct, body segment, data segment, stack, register content, page table, etc.

1) tast_struct

It is a data structure that stores process description information, such as pid, uid, status, signal item, and open file table. It is an important basis for process management and scheduling.

2) User stack and core Stack

As the name suggests, a user stack is a stack used by processes in the user State. It contains parameters and local variables for function calls during user State execution; the core stack is the stack used by the process to run in the core State. It stores the parameters and call sequence used to call system functions. The pointers of the two stacks are saved in the tast_struct structure.

3) registers

Saves program counters, status characters, General registers, and stack pointers.

4) page table

Linear address-to-physical address ing

5) body segment and data segment.

Ii. Linux Process status

There are five processes in Linux: Ready, can interrupt sleep, can not interrupt sleep, pause, frozen. That is to say, linux does not distinguish between readiness and running. They are all called readiness. The status of the process is recorded in tast_struct.

3. Process Control

1) process tree Formation

After the computer starts, the BIOS loads the system boot program from the disk boot sector. It loads the Linux system into the memory and jumps to the kernel for execution. Then the Linux Kernel performs initialization: hardware initialization, internal data structure initialization, and process creation 0. Process 0: Creates process 1. Process 1 is the ancestor of all created processes in the future. It initializes all user processes. Process 1 creates a shell process, and the shell process displays a prompt, waiting for command input.

2) Process Creation

Any user process is created by an existing process. The process must be created by fork and exec. Fork allocates a data structure for the new process and copies the context information of the parent process. Exec transfers the body and data of the executable file to the memory to overwrite the original (copied from the parent process) and starts executing the body segment.

3) Process Termination

The system calls exit () to terminate itself. exit releases all contexts except tast_struct. After the parent process receives the message terminated by the child process, it releases the tast_struct of the child process.

4) Process Scheduling

The scheduling of a process is completed by schedule (). In one case, when the processor switches from the core State to the user State, it checks whether the scheduling flag is 1. If it is 1, run schedule () to schedule the process. In another case, the process is scheduled when the process automatically abandons the processor.

The scheduling process of a process is divided into two steps. First, use the relevant policies to select the process to be executed, and then switch the context.

4. Process Communication

The communication policies of processes include: messages, pipelines, message queues, shared storage areas, and semaphores.

1) Information

The message mechanism is mainly used to transmit Soft Interrupt signals between processes and notify the other party of asynchronous events. The sending process sends the signal (Agreed symbol) to the signal entry in tast_struct of the target process. When the receiving process sees a message, it calls the corresponding processing program. Note, the handler can be executed only when the process is executed and cannot respond immediately.

2) Pipelines

I understand that two processes use a queue in the buffer zone (one for each two processes) to send data to the MPs queue entry and receive data read from the MPs queue exit.

3) Message Queue

Message Queue is a message linked list maintained by the operating system. The sending process adds messages to the queue based on the message identifier, and the receiving process reads messages from the queue.

4) shared storage Zone

A process is shared when a region is opened in the memory. That is to say, a process can attach it to its own address space to operate the data in this region.

5) semaphores

Control Process synchronization.

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.