Unix strace 命令

发布于 2024-09-15 14:13:25 字数 878 浏览 1 评论 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 写=3,5。请注意,这是 独立于正常的追踪 write(2) 系统调用是 由选项-e控制 跟踪=写入。

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

I found the following bash script in order to monitor cp progress.

#!/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
}

I don't understand the "-ewrite" option for the strace command. The closest thing I've found is the man page for strace which is

-e write=set Perform a full hexadecimal and ASCII dump of all the
data written to file descriptors
listed in the specified set. For
example, to see all output activity on
file descriptors 3 and 5 use -e
write=3,5. Note that this is
independent from the normal tracing of
the write(2) system call which is
controlled by the option -e
trace=write.

However I don't understand what the -ewrite option does.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月寒剑心 2024-09-22 14:13:25

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

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

<前><代码> [限定符=][!]值1[,值2]...

其中限定符是跟踪、缩写、详细之一,
raw、signal、read 或 write 和 value 是一个 quali-
与 fier 相关的符号或数字。默认质量
ifier 是踪迹。使用感叹号表示否定
值的集合。例如,-eopen 表示 lit-
erally -e trace=open 意味着仅跟踪
开放系统调用。相比之下,-etrace=!open
表示跟踪除 open 之外的每个系统调用。在
此外,特殊值 all 和 none 具有
明显的含义。

请注意,某些 shell 使用感叹号
历史扩展甚至在引用的论点中也是如此。如果
因此,您必须使用转义符来转义感叹号
反斜杠。

-ewrite means that only the "write" system call will be traced.

-e expr A qualifying expression which modifies which events
to trace or how to trace them. The format of the
expression is:

                     [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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文