(TLDR Doug O'Neal's strace -f -e execve ./myprogram
solved me problem)
I start a program on the command line. The executing program spawns processes. I would like to see or log the names of all processes spawned by the program.
Details
I've tried top
with forest view V:
$ top -c -d 1
Only the parent program is briefly visible. I suspect the refresh rate is too slow to show the child processes.
I've tried to filter by COMMAND=myprogram
but this most probably filters out the child processes.
The parent program spawns processes but I am not sure if top's forest view will show those new processes indented under the original process or independently. I'm not sure if a spawned process can be independent of the parent.
Update #1
I tried this answer with the sleep removed.
#!/bin/bash
mkdir -p "$HOME/ps_logs"
while true; do
ps faux > "$HOME/ps_logs/ps_$(date +%Y-%m-%d_%H:%M:%S).log"
done
I filtered the output with:
grep -rnw './' -e 'myprogam'
All the files only contain myprogram
. So how do I know if myprogram
even spawns any processes?
pstree
? – steeldriver Jul 05 '18 at 12:08$!
to immediately get its PID to pass to pstree e.g../yourprog & pstree -p $!
– steeldriver Jul 05 '18 at 12:24strace -f -e execve ./myprogram
? Doesn't have the problem of trying to shell out another command before your program actually exits. – doneal24 Jul 05 '18 at 12:53