Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What do Linux's User space and Kernel space mean?

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the meaning of User space and Kernel space of Linux". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what do User space and Kernel space of Linux mean?"

When learning Linux, you can often see two words: User space (user space) and Kernel space (kernel space).

To put it simply, Kernel space is the running space of the Linux kernel, and User space is the running space of user programs. For security, they are isolated, and even if the user's program crashes, the kernel is not affected.

Kernel space can execute arbitrary commands and call all the resources of the system; User space can only perform simple operations, can not directly call system resources, and must pass through the system interface (also known as system call) to issue instructions to the kernel.

Str = "my string" / / user space x = x + 2 / / user space file.write (str) / / switch to kernel space y = x + 4 / / switch back to user space

In the above code, the first and second lines are simple assignment operations that are performed in User space. If you need to write to the file on the third line, you have to switch to Kernel space, because the user cannot write the file directly and must be arranged through the kernel. The fourth line is the assignment operation again, so switch back to User space.

To view the allocation of CPU time between User space and Kernel Space, you can use top

Orders. Its third line of output is CPU time allocation statistics.

There are eight statistical indicators in this line.

Of these, the first item 24.8 us (abbreviation for user) is the percentage of time CPU spent in User space, and the second item 0.5 sy (abbreviation for system) is the percentage of time spent in Kernel space.

Casually talk about the meaning of the other six indicators.

Abbreviation for ni:niceness, the percentage of time CPU spent in the nice process (low priority)

Abbreviation for id:idle, the percentage of time CPU spent in idle processes. The lower this value, the busier CPU is.

The abbreviation of wa:wait, the percentage of time that CPU waits for external I wa:wait O, during which CPU cannot do anything else, but does not perform operations. This value is too high to indicate that there is something wrong with the external device.

Abbreviation for hi:hardware interrupt, percentage of time that CPU responds to hardware interrupt requests

Abbreviation for si:software interrupt, the percentage of time that CPU responds to software interrupt requests

Abbreviation for st:stole time, which is valid only for virtual machines and indicates the percentage of CPU time allocated to the current virtual machine that was stolen by other virtual machines on the same physical machine

If you want to see the time-consuming of a single program, you usually use the time command.

Add the time command before the program name, and three lines of statistics will be displayed by default after the program has been executed.

Real: the total time the program runs from start to finish, which is the time that the user can perceive, including the time when CPU switches to perform other tasks.

User: the time the program was executed in User space

Sys: the time the program was executed in Kernel space

The sum of user and sys, in general, should be less than real. But in the case of multicore CPU, these two metrics reflect the total time consumed by all CPU, so the sum of them may be greater than real.

At this point, I believe you have a deeper understanding of "what Linux User space and Kernel space mean". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report