进程的用户时间和系统时间

来源:互联网 发布:iphone打开数据连接 编辑:程序博客网 时间:2024/05/01 15:46
1. 时钟时间(墙上时钟时间wall clock time):就是一个进程从开始运行到结束运行后,时钟走过的时间,这其中包含了进程在阻塞和等待状态的时间。
用户CPU时间:就是用户的进程获得了CPU资源以后,在用户态执行的时间。

系统CPU时间:用户进程获得了CPU资源以后,在内核态的执行时间。

User Time
This is the amount of time the command spends in "User Mode." User Mode is a "safety" feature because when a program is in User Mode it cannot cause other programs to crash, or behave unexpectedly.
System Time
System Time is the amount of time the command spends in "Kernel Mode." There are certain tasks a command must run in Kernel Mode to accomplish, however since a command can misbehave while in Kernel Mode, they only go into Kernel Mode when they have to do so.

 进程的三种状态为阻塞、就绪、运行。
时钟时间 = 阻塞时间 + 就绪时间 +运行时间
 用户CPU时间 = 运行状态下的用户空间时间
 系统CPU时间 = 运行状态下系统空间的时间。

   用户CPU时间+系统CPU时间=运行时间。

2. 

【命令】time — 执行命令并计时

【格式】time [-p] command [arguments...]

【说明】

执行命令行"command [arguments...]",命令行执行结束时在标准输出中打印执行该命令行的时间统计结果,其统计结果包含以下数据:

1)实际时间(real time): 从command命令行开始执行到运行终止的消逝时间;

2)用户CPU时间(user CPU time): 命令执行完成花费的用户CPU时间,即命令在用户态中执行时间总和;

3)系统CPU时间(system CPU time): 命令执行完成花费的系统CPU时间,即命令在核心态中执行时间总和。

其中,用户CPU时间和系统CPU时间之和为CPU时间,即命令占用CPU执行的时间总和。实际时间要大于CPU时间,因为Linux是多任务操作系统,往往在执行一条命令时,系统还要处理其它任务。

另一个需要注意的问题是即使每次执行相同命令,但所花费的时间也是不一样,其花费时间是与系统运行相关的。

例1:

            1. # time date
            2. Sun Mar 26 22:45:34 GMT-8 2006
            3. 
            4. real    0m0.136s
            5. user    0m0.010s
            6. sys     0m0.070s
            7. #


在例1中,执行命令"time date"(见第1行)。系统先执行命令"date",第2行为命令"date"的执行结果。第3-6行为执行命令"date"的时间统计结果,其中第4行"real"为实际时间,第5行"user"为用户CPU时间,第6行"sys"为系统CPU时间。以上三种时间的显示格式均为MMmNN[.FFF]s。

在例1中,CPU时间 = 用户CPU时间 + 系统CPU时间 = 0m0.010s + 0m0.070s = 0m0.080s,实际时间大于CPU时间,说明在date命令运行的同时,还有其它任务在运行。


 
原创粉丝点击