【问题标题】:C shell printing out the current CPU time?C shell打印出当前的CPU时间?
【发布时间】:2012-10-08 18:23:46
【问题描述】:

简单的问题...我只想在脚本中的各个位置打印出 CPU 时间,以查看执行所需的时间。

谢谢。

【问题讨论】:

  • 明确一点:您想要 CPU 时间还是挂钟时间?
  • CPU 时间如果可能的话,如果没有,我会选择小时/分钟/秒时间戳,因为无论如何我要测试的东西都需要几个小时才能运行。

标签: shell time csh


【解决方案1】:

日期 +%s.%N

应该(没有测试)在秒点纳秒上打印出 Unix 时间(当然不是那么准确)。

【讨论】:

    【解决方案2】:

    从字面上回答你的问题,

    您需要查阅系统手册页以获取 ps,以查看必须传递哪些选项才能查看 CPU 时间。它可能会显示在默认视图之一中。然后你需要运行一个并行进程来执行你的ps .... cmd.,在一个循环中,类似于sleep 1。或者,您需要在后台运行您的 c-shell 启动进程,并在 cmd 末尾使用 '&' 字符,然后使用 ps ... ; sleep 1; 构建循环以查看状态。

    但是.. 为什么不只是在脚本的每个片段之前和之后添加添加消息,即。

    echo "P1 start : current time is `date`"
    longrunningProcess1
    echo "P1 end : current time is `date`"
    
    echo "P2 start : current time is `date`"
    longrunningProcess2
    echo "P2 end : current time is `date`"
    

    IHTH

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 2018-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-08
      • 2015-02-01
      相关资源
      最近更新 更多