【问题标题】:Unix strace commandUnix strace 命令
【发布时间】:2010-08-23 13:50:46
【问题描述】:

为了监控 cp 进度,我找到了以下 bash 脚本。

#!/bin/sh
cp_p()
{
   strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
      | awk '{
        count += $NF
            if (count % 10 == 0) {
               percent = count / total_size * 100
               printf "%3d%% [", percent
               for (i=0;i<=percent;i++)
                  printf "="
               printf ">"
               for (i=percent;i<100;i++)
                  printf " "
               printf "]\r"
            }
         }
         END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
}

我不明白 strace 命令的“-ewrite”选项。我发现的最接近的是 strace 的手册页,即

-e write=set 对所有文件执行完整的十六进制和 ASCII 转储 写入文件描述符的数据 列在指定的集合中。为了 例如,查看所有输出活动 文件描述符 3 和 5 使用 -e 写=3,5。请注意,这是 独立于正常的追踪 write(2) 系统调用是 由选项 -e 控制 跟踪=写。

但是我不明白 -ewrite 选项的作用。

【问题讨论】:

  • 您是否从这里@chris-lamb.co.uk/2008/01/24/… 获得了代码,并且您是否尝试过使用安全复制scp 的替代技术?顺便说一句,您应该已经指定了脚本的来源...
  • 细节点:strace 主要是 Linux,尽管它也可能在其他一些平台上可用。例如,Solaris 使用truss 或 Dtrace 系统;我永远记不起 HP-UX 和 AIX 上的等价物是什么。
  • @tommieb75 是的,我从那里得到了脚本。

标签: unix strace


【解决方案1】:

-ewrite 表示只跟踪“write”系统调用。

-e expr 修饰哪些事件的限定表达式 追踪或如何追踪它们。的格式 表达式是:

                     [qualifier=][!]value1[,value2]...

          where qualifier is one of trace,  abbrev,  verbose,
          raw,  signal,  read, or write and value is a quali-
          fier-dependent symbol or number.  The default qual-
          ifier  is trace.  Using an exclamation mark negates
          the set of values.  For example, -eopen means  lit-
          erally -e trace=open which in turn means trace only
          the open system call.  By  contrast,  -etrace=!open
          means  to  trace every system call except open.  In
          addition, the special values all and none have  the
          obvious meanings.

          Note that some shells use the exclamation point for
          history expansion even inside quoted arguments.  If
          so,  you  must  escape the exclamation point with a
          backslash.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-12
    • 1970-01-01
    • 2016-06-09
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多