What do 'real', 'user' and 'sys' mean in the output of time(1)?

前端 未结 7 615
执笔经年
执笔经年 2020-11-22 00:35
$ time foo
real        0m0.003s
user        0m0.000s
sys         0m0.004s
$

What do \'real\', \'user\' and \'sys\' mean in the output of time?

7条回答
  •  遇见更好的自我
    2020-11-22 00:42

    In very simple terms, I like to think about it like this:

    • real is the actual amount of time it took to run the command (as if you had timed it with a stopwatch)

    • user and sys are how much 'work' the CPU had to do to execute the command. This 'work' is expressed in units of time.

    Generally speaking:

    • user is how much work the CPU did to run to run the command's code
    • sys is how much work the CPU had to do to handle 'system overhead' type tasks (such as allocating memory, file I/O, ect.) in order to support the running command

    Since these last two times are counting 'work' done, they don't include time a thread might have spent waiting (such as waiting on another process or for disk I/O to finish).

    real, however, is a measure of actual runtime and not 'work', so it does include any time spent waiting.

提交回复
热议问题