gpt4 book ai didi

linux - 在 shell 脚本中使用 strace 监控所有正在运行的进程

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:25:47 26 4
gpt4 key购买 nike

我想使用 strace 监控所有正在运行的进程,当进程结束时,strace 的输出应该发送到一个文件。

以及如何找到每个正在运行的进程 PID。我还想在输出文件中包含进程名称。

最佳答案

$  sudo strace -p 1725 -o firefox_trace.txt

$ tail -f firefox_trace.txt

1725 将是您要监视的进程的 PID(您可以使用“ps -C firefox-bin”找到 PID,示例中的 firefox)

firefox_trace.txt 将是输出文件!

得到的方法是找到每一个运行的proc PID,并使用命令将它们写入输出文件!


考虑到 doc ,-p 进程号

Attach to the process with the process ID pid and begin tracing. The trace may be terminated at any time by a keyboard interrupt signal ( CTRL -C). strace will respond by detaching itself from the traced process(es) leaving it (them) to continue running. Multiple -p options can be used to attach to up to 32 processes in addition to command (which is optional if at least one -p option is given).

关于linux - 在 shell 脚本中使用 strace 监控所有正在运行的进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35364695/

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