linuxunixprocesspid

How to monitor process status during process lifetime


I need to track the process status ps axf during executable lifetime. Let's say I have executable main.exec and want to store into a file all subprocess which are called during main.exec execution.

 $ main.exec &
 $ echo $! # and redirect every ps change for PID $! in a file.

Solution

  • strace - trace system calls and signals

    $ 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.