可以转载, 转载时务必以超链接形式标明文章原始出处和作者信息及版权声明 链接:http://www.lansz.com/html/2009/11/time-command-in-linux.html 在Linux中存在两个time,一个是bash的命令,另外一个是程序/usr/bin/time,bash的time命令只能很简单的显示程序执行的时间,而/usr/bin/time程序可以显示很详细的与IO相关的数据,比如从内存中读取了多少数据,从磁盘中读取了多少数据之类的,以及文件系统的页大小。通过type命令我们可以看到Linux中的两个timeOracle@linux[]:~ $type -a time time is a shell keyword time is /usr/bin/time bash中的time示例oracle@linux[]:~ $time echo test testreal 0m0.000s user 0m0.000s sys 0m0.000s bash中的time命令只能显示你程序的执行时间,包括实际执行时间,用户时间和系统时间,除此之外没有其他的信息。而time程序就不一样了,它可以提供很详尽的信息,而且还能够定制time程序的输出结果,具体的可以通过man time查看,这里仅仅列举下time -v参数下的数据显示。oracle@linux[]:~ $/usr/bin/time -v echo test test Command being timed: "echo test" User time (seconds): 0.00 System time (seconds): 0.00 Percent of CPU this job got: 0% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.01 Average shared text size (kbytes): 0 Average unshared data size (kbytes): 0 Average stack size (kbytes): 0 Average total size (kbytes): 0 Maximum resident set size (kbytes): 0 Average resident set size (kbytes): 0 Major (requiring I/O) page faults: 113 Minor (reclaiming a frame) page faults: 16 Voluntary context switches: 0 Involuntary context switches: 0 Swaps: 0 File system inputs: 0 File system outputs: 0 Socket messages sent: 0 Socket messages received: 0 Signals delivered: 0 Page size (bytes): 4096 Exit status: 0 从上面的输出结果我们可以看到,除了CPU时间之外,通常我们还关心下面几个:Major (requiring I/O) page faults 从磁盘中读取了多少页的数据。 Minor (reclaiming a frame) page faults 从操作系统缓存中读取了多少页的数据。 Swaps 进程被swap出内存的次数。 File system inputs/outputs 从文件系统中读取/写入的数据数量。 Page size (bytes) 操作系统的页大小。