In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you the basis of Linux kernel process management, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
The kernel describes the process through task_struct
Use the command pstree to let the kernel list the relationships between processes in a tree structure, as shown in the following figure:
This is the structure of processes in the kernel, so how does the kernel manage and describe these processes in a tree structure? The data structure used to describe the process can be understood as the properties of the process. For example, the state and PID of the process are encapsulated in the data structure of the process descriptor task_struct.
Struct task_struct {. / *-1 unrunnable, 0 runnable, > 0 stopped: * / / task status. 0 is the stop state. Volatile long state;. / / the pointer to the kernel stack void * stack;. / * there are 6 scheduling strategies for processes. * deadline process scheduling policy: SCHED_DEADLINE. * Real-time process scheduling policy: SCHED_FIFO,SCHED_RR. * ordinary process scheduling policy: SCHED_NORMAL,SCHED_BATCH,SCHED_IDLE. * / unsigned int policy;. / / process memory management information struct mm_struct * mm; struct mm_struct * active_mm;. / / process identifier, which is used to represent a process pid_t pid;. / / thread linked list struct list_head thread_group; struct list_head thread_node; struct completion * vfork_done;. / * Filesystem information: * / / File system information struct fs_struct * fs; / * Open file information: * / / Open file information struct files_struct * files;. / * CPU-specific state of this task: * / the CPU status of the process. When switching, save the struct thread_struct thread; to the task_struct where the process is stopped. }
The kernel manages each process relationship in a tree structure through the list_head linked list.
There are too many task_struct structures. Only some member variables are listed here. Readers who are interested can go to the source code include/linux/sched.h header file to see it.
Main categories of information in task_struct:
Identifier: a unique identifier pid that describes this process and is used to distinguish other processes.
Status: task status, exit code, exit signal, etc.
Priority: priority over other processes
Program counter: the address of the next instruction to be executed in the program
Memory pointers: pointers to program code and process-related data, as well as pointers to blocks of memory shared with other processes
Context data: data in the registers of the processor when the process is executing
Icano status information: including the displayed Ipicuro request, the assigned process Iripple O device, and the list of files used by the process
Accounting information: may include the sum of processor time, the sum of clocks used, time limits, accounting numbers, etc.
ARM64 does not need to get the current task_struct through struct thread_info thread_info
Static _ _ always_inline struct task_struct * get_current (void) {unsigned long sp_el0; asm ("mrs% 0, sp_el0": "= r" (sp_el0)); return (struct task_struct *) sp_el0;} # define current get_current ()
You can see that sp_el0 is returned directly as task_struct. For the ARM64 platform, the task_struct address of the current process is recorded using the sp0_el1 register, which records the task_struct address of the currently running process when the kernel performs a process switch. Therefore, it is also very easy for us to find task_struct in current, and we no longer need to locate through sp and thread_info.
Volatile long state
-1 is not running, = 0 is running state, > 0 is stopped state
Both ready and running in Linux correspond to TASK_RUNNING flag bits. Ready indicates that the process is in queue and has not been scheduled, while running indicates that the process is running on CPU.
Void * stack
A pointer to the kernel stack where the kernel allocates kernel stack space for each process through dup_task_struct and records it here.
Struct mm_struct * mm
Information related to the process address space.
Allocation and initialization of task_struct
As you can see in the figure, when the upper application creates a process in various ways, it will eventually create a new task_struct through _ do_fork.
The above is the basis of process management in the Linux kernel. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are 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.