为什么在linux time命令有不同的输出,当我在锅壳式比我在脚本中使用它? [英] Why time command in linux has different output when I type it in shell than I use it in script?
本文介绍了为什么在linux time命令有不同的输出,当我在锅壳式比我在脚本中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题是,当我在shell中使用的时间,我得到这样的输出:
1.350u 0.038s 0:01.45 95.1%0 + 0 0K + 72io 1pF的+0瓦特
当即时通讯在脚本中使用它,我得到:
真正0m1.253s
用户0m1.143s
SYS 0m0.047s
我的意思是为什么呢?而在一开始shell脚本我写的:
#!/斌/庆典
解决方案
Bash有一个内置的命令时间
,和您的系统还应该有一个单独的二进制的/ usr / bin / time会
:
$帮助时间
时间:时间[-p]管道
报告流水线执行消耗的时间。 执行管道和打印的实时摘要,用户CPU时间,
...
$其时
在/ usr / bin / time会
这两个命令产生不同的输出:
$时间回声喜
嗨真正0m0.000s
用户0m0.000s
SYS 0m0.000s
$在/ usr / bin / time会回应喜
嗨
0.00user 0.00system 0:00.00elapsed 100%的CPU(0avgtext + 0avgdata 0maxresident)K
0inputs + 0outputs(0major + 199minor)页面错误0swaps
The problem is when I use time in shell I get output like that:
1.350u 0.038s 0:01.45 95.1% 0+0k 0+72io 1pf+0w
And when Im using it in script I get:
real 0m1.253s
user 0m1.143s
sys 0m0.047s
I mean why? And in shell script at the beginning I write:
#!/bin/bash
解决方案
Bash has a built-in command time
, and your system should also have a separate binary at /usr/bin/time
:
$ help time time: time [-p] pipeline Report time consumed by pipeline's execution. Execute PIPELINE and print a summary of the real time, user CPU time, ... $ which time /usr/bin/time
The two commands produce different outputs:
$ time echo hi hi real 0m0.000s user 0m0.000s sys 0m0.000s $ /usr/bin/time echo hi hi 0.00user 0.00system 0:00.00elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+199minor)pagefaults 0swaps
这篇关于为什么在linux time命令有不同的输出,当我在锅壳式比我在脚本中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文