monitor multiple pids with top
5,296
How about something like
pids=( $(pgrep 'postgres|unicorn|nginx') )
to put the PIDs in an array, and then
top "${pids[@]/#/-p }"
to spit them back out into top
, prepending each with -p
Related videos on Youtube
Author by
lfender6445
Updated on September 18, 2022Comments
-
lfender6445 almost 2 years
I want to monitor memory usage for several processes and came up with a command like this:
ps aux |grep -e postgres -e unicorn -e nginx|cut -d' ' -f2|for i in $(xargs); do echo $i; done 16112 16113 ...
How can I change the bit after the last pipe to feed arguments into
top -p $i
, so I get an of overall idea of memory consumption for all pids? The final command would produce something liketop -p<pid1> -p<pid2>
and so on -
lfender6445 over 9 yearsvery short and clever technique, this will prove useful for me in many scenarios