gpt4 book ai didi

linux - 从 strace 输出中提取系统调用名称

转载 作者:太空宇宙 更新时间:2023-11-04 10:04:43 28 4
gpt4 key购买 nike

我使用以下命令从 strace 输出中提取系统调用名称:

strace ls 3>&1 1>&2 2>&3 3>&- | grep -P -o '^[a-z]*(?=\()'

但此命令还在输出中包含 ls 输出。我怎样才能防止这种情况发生?

最佳答案

strace 有两个选项可以帮助您获得所需的内容:

  • -c 将输出该命令运行的所有系统调用的表格,以及它们被调用的次数和 CPU 使用率。
$ strace -c lsDesktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos% time     seconds  usecs/call     calls    errors syscall------ ----------- ----------- --------- --------- ---------------- 31.07    0.000653          20        32           mmap  9.94    0.000209          20        10           mprotect  9.80    0.000206          12        16           read  8.28    0.000174          15        11           close  7.61    0.000160          16        10           fstat  6.90    0.000145          16         9           openat  2.47    0.000052          17         3         3 ioctl...
  • The -o option will send strace's output to a file, so it won't get mixed in with your process's output.

The following will run the ls command, diverting its output to /dev/null, and will send strace's output to an awk script to extract the last column:

$ strace -o >(awk '$1 ~ /^-----/ { toprint = !toprint; next } { if (toprint) print $NF }') \
-c ls >/dev/null 2>/dev/null
mmapmprotectreadclosefstatopenatioctl...

关于linux - 从 strace 输出中提取系统调用名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53370463/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com