Let’s first talk about the reason I started looking for this. I have a couple of services running in Ubuntu including DBs like MySQL, MongoDB, etc. along with running nGinx and other services.
However, sometimes, I noticed that the memory consumption goes upwards and it’s wise to know which process could be responsible for this.
I decided to look into this using the ps command
ps -eo pmem,pcpu,pid,args | tail -n +2 | sort -rnk 1 | head
Let’s look at the arguments provided:
|Current process snapshot report
|Select all processes. Identical to -A.
|format is a single argument in the form of a blank-separated or comma-separated list, which offers a way to specify individual output columns.
|the ratio of the process’s resident set size to the physical memory on the machine, expressed as a percentage.
|CPU utilization of the process in the “##.#” format. Currently, it is the CPU time used divided by the time the process has been running (cputime/real time ratio), expressed as a percentage.
|A number representing the process ID
|Command with all its arguments as a string.
|tail -n +2
|Output lines starting to the second line
|sort -rnk 1
|r (reverse) n(numeric sort) by column 1 i.e., pmem
|Output the first 10 lines
Hope it helps!