Linux 时间命令——真实 vs 用户 vs 系统

标签 linux linux-kernel executable-jar

我在 Linux 中使用时间命令运行一个 jar 文件。下面是执行后的输出。

15454.58s real 123464.61s user  6455.55s system

下面是执行的命令。

time java -jar -Xmx7168m Batch.jar

但执行该过程实际花费的时间是 9270 秒。

为什么实际时间(挂钟时间)和实际时间不同?

谁能解释一下?它在多核机器(32 核)上运行。

最佳答案

也许这可以解释您遇到的偏差。来自时间 Wikipedia article :

Because a program may fork children whose CPU times (both user and sys) are added to the values reported by the time command, but on a multicore system these tasks are run in parallel, the total CPU time may be greater than the real time.

除此之外,你对实时的理解符合time(7)中给出的定义:

Real time is defined as time measured from some fixed point, either from a standard point in the past (see the description of the Epoch and calendar time below), or from some point (e.g., the start) in the life of a process (elapsed time).

另请参阅 bash(1)(尽管其关于 time 命令的文档并不太全面)。

如果秒数对您来说足够精确,这个小包装器可以提供帮助:

#!/bin/bash

starttime=$( date +"%s" )
# run your program here
endtime=$( date +"%s" )

duration=$(( endtime-starttime ))
echo "Execution took ${duration} s."

注意:如果在程序运行时更改系统时间,结果将不正确。

关于Linux 时间命令——真实 vs 用户 vs 系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29121668/

相关文章:

在 "perf"事件处捕获用户空间变量

c - 为什么 Linux 内核不使用大页面?

linux - 在 Debian 打包期间运行脚本

linux - 如何在 vi 编辑器或 linux 中查找和删除两个文件中的重复行

mysql - 无法在 elementaryos 上安装 mysql 5.6

linux - Linux 中的页面错误是否一定会导致上下文切换?

java - 使用 JAR 导出图像/文本文件

java - 使用 JDeveloper 构建 Java 整个项目 jar

java - 运行 Eclipse 创建的 JAR 时未显示图像

javascript - 如何去除 Centos 7 桌面 (Hot Corner) 右上角的效果?