【问题标题】:Determine command line arguments a program uses to launch another one?确定程序用于启动另一个程序的命令行参数?
【发布时间】:2018-08-01 19:21:17
【问题描述】:

动机:当我运行grub-mkrescue 时,它会在内部启动xorriso 来编写一个iso 文件。我想看看正在传递哪些命令行参数xorriso。我知道我可以查看grub-mkrescue 的来源,但我现在对通用解决方案感兴趣。我尝试使用strace,但输出没有说明。

strace grub-mkrescue -o foo.iso iso/

有没有办法做到这一点?

【问题讨论】:

  • 你能写完整行吗?考虑到 xorriso 完成时间不到 1 秒
  • ps -fC xorriso 在运行时。
  • 通常,大多数程序都有一个“详细”选项来获得更详细的输出。尝试使用 -v 或 --verbose 运行 grub-mkrescue。甚至可能是-V。
  • 它会在 execve 之前分叉,所以你不会用 strace 看到它,除非你使用 -f 来关注孩子
  • @thatotherguy 你的答案是正确的,贴出来这样我就可以将此问题标记为已解决!

标签: linux bash process command-line-arguments


【解决方案1】:

一个进程在运行execve之前会fork,所以它不会出现在父进程的strace中。

使用strace -f 也可以关注孩子。

【讨论】:

  • strace -f grub-mkrescue -o foo.iso iso/ | grep xorriso 调用它完美地做到了!
【解决方案2】:

您可以用更详细的替换 xorriso:

which xorisso
cd $(dirname $(which ps))
mv xorisso xorisso.org
test -f xorisso | echo "mv failed, stop here" 

cat <<'@' > xorisso
echo "$0 $@" > /tmp/xorisso_call.tmp
"$0.org" "$@"
@
chmod +x xorisso

【讨论】:

    猜你喜欢
    • 2013-01-27
    • 1970-01-01
    • 2013-04-25
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    相关资源
    最近更新 更多