0

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

#!/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 write=3,5。请注意,这与 write(2) 系统调用的正常跟踪无关,后者由选项 -e trace=write 控制。

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

4

1 回答 1

4

-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.
于 2010-08-23T13:55:56.930 回答