从 strace 打印输出中抽取几行样本

从 strace 打印输出中抽取几行样本

我有一个进程,我想用 strace 检查,但由于它打印出很多东西,我想每 X 秒只采样几行。有没有办法用 bash 或类似的方法做到这一点?

例如:

strace -p 123456 | "print out most recent 80 lines every 2 seconds"

答案1

是的:

strace -p $PID >$PID.log &
watch tail -n80 $PID.log >$PID-sample.log &
tail -f $PID-sample.log

或者只是watch tail -n$LINES $PID.log如果您不需要向后滚动采样日志。

相关内容