0

Using ps aux --sort rss, I can get a list of processes with ascending order of memory consumption. Is there a way in ps to get the list of processes with a certain memory consumption?

i.e. something along the lines "list all processes where rss and vsz equal 0" for example kernel threads.

1
  • @JuliePelletier I know this can be done using filters but as the question mentions, I was wondering whether ps provides such functionality out of the box. :) – Siddharth Shukla Sep 6 '16 at 0:20
3

A simple awk filter could be used.

We know, from ps aux output that vsz is column 5 and rss is column 6 so we can do

ps aux --sort rss | awk '$5 == 0 && $6 == 0'

That will only display the fields where both values are zero.

If you also want the header

ps aux --sort rss | awk 'NR==1 || ($5 == 0 && $6 == 0)'
2
  • thanks for the answer. However, I was looking for a way to do it without filters. Maybe I should have made that more clear in the question. – Siddharth Shukla Sep 6 '16 at 0:22
  • 2
    It can't be done inside ps. That also goes against the Unix philosophy; why add filters to every single command when we can post-process output? – Stephen Harris Sep 6 '16 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.