Continuously monitor a process and all its children with `top`?
2
votes
5
answers
1388
views
I want to run a process that spawns children, e.g.,
for i in {1..4}; do
sh -c 'echo $$; for j in {1..3}; do
sh -c "echo ...\$\$; sleep 1"
done'
done
and I would like to monitor the CPU and memory usage every 2 seconds with top
.
- I can monitor its resource usage with top -p
, but this doesn't account for the children.
- I can monitor _all_ running processes just with top
, but this is too much information.
- I can precompute a list of PIDs, then pass all of them to top
, but the process could then spawn new children, which would not be accounted for.
How can I get a top
snapshot every 2 seconds of just the process I'm running and any processes it spawns?
Someone asked a similar question [here](https://unix.stackexchange.com/questions/178795/how-can-i-find-the-cpu-resource-utilization-of-a-process-and-all-its-children) , but it was about summarizing this information into a *single* number, after the process finishes. My question is about *continuously* monitoring the processes while they’re still going.
Asked by wobtax
(1135 rep)
Jun 25, 2024, 06:54 PM
Last activity: Jun 27, 2024, 06:01 PM
Last activity: Jun 27, 2024, 06:01 PM