time命令_Linux time命令:测量命令的执行时间或者系统资源的使用情况

time 的简单用法

如果你想查看一条命令(比如 ls)到底执行了多长时间,我们可以这样做:

[roc@roclinux ~]$ time ls
program  public_html  repo  rocscm
 
real    0m0.002s
user    0m0.002s
sys 0m0.000s


(1) real:从进程 ls 开始执行到完成所耗费的 CPU 总时间。该时间包括 ls 进程执行时实际使用的 CPU 时间,ls 进程耗费在阻塞上的时间(如等待完成 me/O 操作)和其他进程所耗费的时间(Linux 是多进程系统,ls 在执行过程中,可能会有别的进程抢占 CPU)。

(2) user:进程 ls 执行用户态代码所耗费的 CPU 时间。该时间仅指 ls 进程执行时实际使用的 CPU 时间,而不包括其他进程所使用的时间和本进程阻塞的时间。

(3) sys:进程 ls 在内核态运行所耗费的 CPU 时间,即执行内核系统调用所耗费的 CPU 时间。

 

实例:

]# time ./ping.sh
172.16.0.4
172.16.0.3
real 0m1.445s

user 0m0.179s
sys 0m0.320s

 

posted on 2020-04-21 16:36  步留痕  阅读(193)  评论(0)    收藏  举报

导航