The ps command in Linux can tell us all sorts of information about the running processes on our system. The command also reports memory usage for each running process. In this tutorial, you’ll see how to list processes on Linux, sorted by their memory consumption.
In this tutorial you will learn:
- How to use
pscommand to sort by memory usage
- How to sort by RAM, VSZ, and RSS columns
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
|Conventions||# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
ps sort by memory
The default output of a
pscommand is sorted by the process number by default. However, this default behavior can be changed with the use of
$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND [...] root 366 0.0 0.0 0 0 ? I< Sep20 0:00 [cryptd] systemd+ 568 0.0 0.6 23904 13120 ? Ss Sep20 0:00 /lib/systemd/systemd-resolved systemd+ 569 0.0 0.2 90260 5968 ? Ssl Sep20 0:00 /lib/systemd/systemd-timesyncd root 598 0.0 0.3 238172 7168 ? Ssl Sep20 0:00 /usr/lib/accountsservice/accounts-daemon root 599 0.0 0.0 2548 772 ? Ss Sep20 0:00 /usr/sbin/acpid avahi 602 0.0 0.1 8532 3300 ? Ss Sep20 0:00 avahi-daemon: running [linuxconfig.local] [...]
Sort by %MEM
Sort by RAM percent usage. Highest values first:
$ ps aux --sort=-%mem or $ ps auxk-%mem
Sort by RSS or VSZ
The RSS and VSZ columns also report RAM usage, though its not as straightforward as the %MEM column. See our guide on RSS vs VSZ to learn the differences between the two types.
The syntax is the same as above. Just specify which column you’d like to sort by.
Sort by RSS usage. Highest values first:
$ ps aux --sort=-rss or $ ps auxk-rss
Sort by RSS usage. Highest values last:
$ ps aux --sort=+rss or $ ps auxk+rss
Please note that the
+ can be omitted as it is a default option and thus making
ps auxkrss and
ps auxk+rss identical.
In this tutorial, we learned how to use the ps command to sort by memory usage. This is one of the quickest ways to see which processes are consuming most of your RAM, and gives us an in-depth view with the the RSS and VSZ columns. There are many other ways you can monitor RAM usage on Linux. Check out our guide on how to monitor RAM usage on Linux to see some other handy commands to do the job.