User space and kernel space (reprint)

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

 

Simply put, Kernel space is space to run the Linux kernel, User space is a space for the user to run the program. For safety, they are isolated, even if the user program crashes, the kernel will not be affected.

 

Kernel space can execute arbitrary commands, all the resources of the system call; User space can only perform simple operations, system resources can not be called directly, you must (also known as system call), in order to issue commands to the kernel via the system interface

 

 

In the above code, the first and second rows are simple assignment operation is performed in User space. The third line needs to write to a file, it is necessary to switch to the Kernel space, since users can not write files directly, you must arrange through the kernel. The fourth line is the assignment operator, will switch back to User space.

View CPU time allocation between the User space Kernel Space, you can use the top command. It's the third line of the output is the CPU time allocation statistics.

 

This line has eight statistical indicators.

 

Wherein, the first 24.8 us (abbreviation of the user) is the CPU time consumption percentage User space, the second 0.5 sy (system abbreviation) is consumed by the percentage of time Kernel space.

Also just talk about the meaning of the other six indicators.

 

If you want to see a single program's time-consuming, generally use the time command.

 

 

 

Plus time command, after the program is finished, the default display three lines of statistics before the program name.

 

 

sys user and the sum, in general, should be less than real. But if it is a multi-core CPU, these two indicators reflects the total time all the CPU, they may be greater than the sum of real.

 

Transfer from: http: //www.ruanyifeng.com/blog/2016/12/user_space_vs_kernel_space.html

Guess you like

Origin www.cnblogs.com/wx170119/p/12034996.html