Could you please help me to sort this out? I'm trying to write a bash script which will monitor ram usage (not only ram but cpu and network as well) and show me 3 processes which use the most ram in past X seconds? I know that I can find which processes use the most ram by running the following:
ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 3
But how can this be repeated? I want to see not the situation at this exactly second, but monitor the situation for (let it be) 60 seconds and see top 3 processes which was using the most ram.
watch "ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 3", you can look into using
top -b` and passing it additional sorting parameters, and there are also other tools likesar
andvmstat
that might be helpful.