万书皆下品,唯有萌最高! 收藏本站
登陆 / 注册 搜索

阅读:3.9K   回复: 1

linux time 命令的输出中 real user sys 含义

[复制链接]
小执念 古黑浩劫论坛大牛 2020-6-9 16:03 |显示全部楼层

可遇不可求的事:故乡的云,上古的玉,随手的诗,十九岁的你。

管理员
Linux 中 time 命令,我们经常用来计算某个程序的运行耗时,用户态cpu耗时,系统态cpu耗时。

如用
  1. time make
复制代码

就可以计算编译程序使用的时间,借一张编译 php8 的图片来说明
🦷🧳🥩🚭🦮‎
linux time 命令的输出中 real user sys 含义 编译php8耗时.png

上图这三个时间都具体代表什么意思呢?

real : 表示 make 程序整个的运行耗时,可以理解为 make 运行开始时刻你看了一下手表,make 运行结束时,你又看了一下手表,两次时间的差值就是本次 real 代表的值.

🧑‍🌾‏🛍🗡😴🤳



user:这个时间代表的是 make 运行在用户态的 cpu 时间,什么意思?

要明白这个问题,就要讲一下用户态核心态

🤳🌕🌶❌🐥‌
引用

核心态(Kernel Mode):

在核心态,代码拥有完全的、不受任何限制的访问底层硬件的能力。可以执行任意的CPU指令,访问任意的内存地址。内核态通常情况下,都是为那些最底层的,由操作系统提供的,可信可靠的代码来运行的。内核态的代码崩溃将是灾难性的,它会影响到整个系统。

  —– In Kernel mode, the executing code has complete and unrestricted access to the underlying hardware. It can execute any CPU instruction and reference any memory address. Kernel mode is generally reserved for the lowest-level, most trusted functions of the operating system. Crashes in kernel mode are catastrophic; they will halt the entire PC.
🤛🚐🆘🦬‎
用户态(User Mode):

在用户态,代码不具备直接访问硬件或者访问内存的能力,而必须借助操作系统提供的可靠的,底层的APIs来访问硬件或者内存。由于这种隔离带来的保护作用,用户态的代码崩溃(Crash),系统是可以恢复的。我们大多数的代码都是运行在用户态的。
👮‍♂️‍👠🔋🤮🤌
—– In User mode, the executing code has no ability to directly access hardware or reference memory. Code running in user mode must delegate to system APIs to access hardware or memory. Due to the protection afforded by this sort of isolation, crashes in user mode are always recoverable. Most of the code running on your computer will execute in user mode.


所以用人话来说 user 这个时间,就是指程序 make 运行在用户态的 CPU 时间(如果是多核/多线程同时工作,那耗时就是多核 CPU 耗时相加),CPU 时间不是墙上的钟走过的时间,而是指CPU工作时间。

sys : 这个时间代表的是 make 运行在核心态的 CPU 时间。
🧑‍🎤‌👠📬🙃🖕
上一篇
下一篇
帖子热度 3947 ℃

行车9 「初入古黑」 2020-6-9 16:03 |显示全部楼层

这个用户很懒,还没有填写自我介绍呢~

好帖必须得顶起
您需要登录后才可以回帖 登录 | 免费注册  

本版积分规则

快速回复 返回列表