2014-11-23 70 views

回答

2

strace的 - 跟蹤系統調用和信號

$ main.exec & 
$ strace -f -p $! -o child.txt 

-f Trace child processes as they are created by currently traced processes as a result of the fork(2), vfork(2) and clone(2) system calls. Note that -p PID -f will attach all threads of process PID if it is multi-threaded, not only thread with thread_id = PID. 
+0

「strace的」就是我要找的。它完美的作品。 謝謝。 – 2014-11-24 18:16:35

1

如果您不能重新編譯和儀器main.exec,ps在一個循環是可以爲你工作一個簡單的選擇:

while true; do ps --ppid=<pid> --pid=<pid> -o pid,ppid,%cpu,... >> mytrace.txt; sleep 0.2; done 

然後相應地處理它的輸出。

top也可以工作,並且可以在批處理模式下運行,但不確定是否可以讓它動態監視像ps這樣的子進程。不要這樣想。

+0

目前我以這種方式正在做(在一個循環PS) – 2014-11-23 03:02:01