In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "sample analysis of Linux system process", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and study the "sample analysis of Linux system process" this article.
1. What is a process?
A process is a general term for a program in execution and all the resources it contains, including virtual processors, virtual spaces, registers, stacks, global data segments, and so on.
In Linux, each process is assigned a data structure called process control block (PCB) when it is created. PCB contains a lot of important information for system scheduling and process execution. The PCB of all processes is stored in kernel space. The most important information in PCB is the process PID, through which the kernel uniquely identifies a process. PID can be recycled, with a maximum value of 32768. The pid of the init process is 1, and all other processes are descendants of the init process.
In addition to the process control block (PCB), each process has an independent kernel stack (8k), a process descriptor structure, which is stored in the kernel space as process control information, while the process user space mainly stores code and data.
two。 The creation of a process
A process creates a new process by calling:: fork (),:: vfork () and:: clone () system calls. In the kernel, they are all implemented by calling do_fork. The traditional fork function directly copies all resources of the parent process to the child process. On the other hand, Linux's:: fork () is implemented using copy-on-write pages, that is, the parent and child processes share the same resource copy, and the data is replicated only when the data changes. Typically, exec () is called immediately after the child process is created, thus avoiding copying all the resources of the parent process.
The differences between the three are as follows:
: fork (): all the data structures of the parent process are copied to the child process (copy the page when writing).
:: vfork (): only task_struct and kernel stacks are copied, so only a thread of the parent process (no independent user space) is generated.
:: clone (): powerful, with a lot of parameters. : clone () allows you to selectively inherit the resources of the parent process, you can choose to share a virtual space with the parent process like:: vfork (), so that what you create is a thread, or you can not share it with the parent process, you can even choose to create a process and the parent process is no longer a father-son relationship, but a brotherly relationship.
3. Revocation of process
The process exits execution by calling exit (), which terminates the process and releases all resources. The parent process can query whether the child process is terminated through wait4 (). The process is in a dead state after exiting execution until its parent process calls wait () or waitpid (). When the parent process exits, the kernel specifies another process of the thread group or the init process as the new parent of its child process. When a process receives a signal that cannot be processed or ignored, or when the kernel produces an unrecoverable CPU exception and the kernel is running on behalf of the process, the kernel can force the process to terminate.
4. Process management
The kernel stores process information in a two-way circular linked list called task queue (task list) (kernel space). Each item in the linked list is of type task_struct, called process descriptor structure (process descriptor), which contains all the information about a specific process, including open files, process address space, pending signals, process status, and so on.
Linux allocates task_struct through the slab allocator, which achieves object reuse and cache shading (resource consumption caused by dynamic allocation and release can be avoided by pre-allocating and reusing task_struct).
The kernel organizes all processes in the TASK_RUNNING state into a runnable bidirectional circular queue. The scheduling function scans the entire runnable queue to get the most worthwhile process into execution. Avoid scanning all processes and improve scheduling efficiency.
5. Kernel stack of the process
Linux allocates a 8KB-sized memory area for each process to hold the process's two different data structures: thread_info and the process's kernel stack.
When a process is in kernel state, it uses a different stack than the user state stack, and the kernel uses very few stacks to control the path, so 8KB is sufficient for stacks and descriptors.
The above is all the contents of the article "sample Analysis of Linux system processes". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.