【问题标题】:How to execute strace for a particular time period如何在特定时间段内执行 strace
【发布时间】:2013-02-19 08:43:24
【问题描述】:

我正在使用“strace”命令记录与 Android 应用相关的系统调用执行情况。

Process process = Runtime.getRuntime().exec("su");
OutputStream os;
os = process.getOutputStream();
os.write("strace -p"+processID+" -o /mnt/sdcard/straceLog.txt".getBytes());
os.close();

我如何才能在任何应用程序的特定时间段(比如 30 秒)内仅对系统调用进行 strace 并在此之后中断 strace 执行..请帮助...

【问题讨论】:

  • strace(至少 Android 版本)似乎没有任何此类选项。可能性可能是在您的 java 应用程序中运行计时器并在一段时间后终止 strace(或父超级用户 shell),或者构建具有时间限制的修改后的 strace。您还可以考虑在 java 中捕获输出,然后根据需要关闭管道,并查看是否由于结束关闭而导致 strace 在 EPIPE 上死亡。

标签: android shell execute strace


【解决方案1】:

使用timeout 程序。

timeout 1 strace -c sleep 5

或合并到OP的问题中:

os.write("timeout 30 strace -p"+processID+" -o /mnt/sdcard/straceLog.txt".getBytes());

这个可能在 Android 上不可用(我不知道),但是当我搜索 running strace time based 时,这个问题是第一个命中,所以希望这可以帮助某人。

【讨论】:

    【解决方案2】:

    在后台进程中运行 strace 并在给定时间后终止该进程。

    Command line command to auto-kill a command after a certain amount of time

    os.write("strace -p"+processID+" -o /mnt/sdcard/straceLog.txt & sleep 30; kill $!".getBytes());

    【讨论】:

      猜你喜欢
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      • 2021-09-18
      • 1970-01-01
      相关资源
      最近更新 更多