linux用户空间与内核空间_查询磁盘空间linux_linux空间

01

前言

最近跟一个大学的师兄聊天,师兄是吉诺比利的忠实粉丝,从大学到现在一直都是用吉诺比利的图片当头像,师兄读完研究生后在大学里面当老师,现在的生活是放假的时候旅游,上课的时候教教书,下课的时候打打球。这样的生活就像陶渊明先生想要的世外桃源吧。跟师兄提到我做了一个嵌入式Linux的公众号,能不能帮我推荐给他的学生,因为看到现在很多出来就业后再培训需要花费非常大的一笔钱,如果有自学的环境就能学好,那是一个非常不错的机会,而学习本来就是一件时间上非常长的事情,掌握学习的方法那才是立于不败之地的根本。

周末的时间很少,晚上楠哥各种玩各种嗨,白天还要带楠哥出去挖沙,就早上的时间是自己的,看了文章的,麻烦点下关注linux空间,有疑问或者有问题的,欢迎留言批评指正,周末愉快!

02

正文

一、什么是内核空间和用户空间

内核空间:针对linux操作系统而言,将最高的1G字节(从虚拟地址到),供内核使用,称为内核空间,内核空间执行的程序一般包括驱动程序,中断程序,内存管理程序

用户空间:将较低的3G字节(从虚拟地址到),供各个进程使用,称为用户空间,运行在用户空间的程序,像我们正常的用户程序,计算器,日历等,但是用户空间的程序可以通过系统调用进入内核,于是,我们从进程的角度看,进程可以享受4G的虚拟内存空间

为什么会分为内核空间和用户空间?

1、 现代CPU,以ARM为例,拥有不同的工作模式,不同的工作模式对CPU寄存器的访问执行权限不一样,对用户开放的权限肯定不能太大,分层次就是为了方便用户和系统的不同权限。

2、 系统调用是一个非常酷的东西,分层次为了统一系统调用接口,方便管理

3、 内存管理,虚拟地址和物理地址,用户如果直接可以访问到物理地址,那是一件非常恐怖的事情。

二、什么是进程上下文与中断上下文

进程上下文:

用户进程在执行系统调用,或者发生一个异常的时候,这时这个进程就进入了内核空间,这时候对内核来说就叫做进程上下文

进程上下文,一定是进行了系统调用或者异常执行,导致CPU从用户空间到内核空间了linux空间,简单理解点,可以把执行在用户空间的代码叫做进程上文,执行在内核空间的叫做进程下文

中断上下文:

当内核在执行一个中断处理函数或者执行中断下半部时,这时候,内核是处在中断上下文

这里引入一个中断下半部,那就应该有中断上半部

中断上半部:触发中断开始到进入中断处理程序的那个点,都可以叫中断上半部

中断下半部:执行中断处理程序的那部分代码

-------------------------------------------

One of the most parts of a is the code. This code is read in from an file and the 's space. in user-space. When a a call or an , it -space. At this point, the is said to be " on of the " and is in . When in , the macro is valid[7]. Upon the , the in user-space, a - has in the , in which case the is to the .

[7] Other than there is , In , the is not on of a , but is an . There is no tied to and no .

calls and are well- into the . A can begin in -space only one of these -- all to the is these .

-------------------------------------------

When an or half, the is in . that is the mode of the is in while it is on of a -- for , a call or a . In , the macro to the task. , a is to the in , can sleep or the .

, on the other hand, is not with a . The macro is not ( it to the ). a , sleep -- how would it ever ?, you call from . If a , you use it from your -- this the that one can call from an .

is time the other code. Code be quick and . Busy is . This is a very point; keep in mind that your has other code ( even on a line!). of this , it is that all be as quick and as as . As much as , work be out from the and in a half, which runs at a more time.

The setup of an 's is a . , did not their own . , they would share the stack of the that they [1]. The stack is two pages in size; , that is 8KB on 32-bit and 16KB on 64-bit . in this setup share the stack, they must be with what data they there. Of , the stack is to begin with, so all code be .

[1] A is . When else is , the idle task runs.

Early in the 2.6 , an was added to the stack size from two pages down to one, only a 4KB stack on 32-bit . This every on the two pages of . To cope with the stack size, were given their own stack, one stack per , one page in size. This stack is to as the stack. the total size of the stack is half that of the stack, the stack space is get the full page of to .

Your not care what stack setup is in use or what the size of the stack is. use an of stack space.

看看我们的公众号吧

此处按一下又不会怀孕

还能教你怎么写好Hello,world


限时特惠:
本站持续每日更新海量各大内部创业课程,一年会员仅需要98元,全站资源免费下载
点击查看详情

站长微信:Jiucxh

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注