Linux认证辅导:Linux中的timeLinux认证考试
文章作者 100test 发表时间 2009:11:15 08:55:20
来源 100Test.Com百考试题网
  在linux中存在两个time,一个是bash的命令,另外一个是程序/usr/bin/time,bash的time命令只能很简单的显示程序执行的时间,而 /usr/bin/time程序可以显示很详细的与IO相关的数据,比如从内存中读取了多少数据,从磁盘中读取了多少数据之类的,以及文件系统的页大小。
  通过type命令我们可以看到Linux中的两个time
  linux">.oracle@linux[]:~
  $type -a time
  time is a shell keyword
  time is /usr/bin/time
  bash中的time示例
  oracle@linux[]:~
  $time echo test
  test
  real    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