0

I am running this approach in order to verify the commands that consuming memory from high to low on linux redhat machine

I wrote this approach as 1024/1024 , in order to get the values in GIGA

ps -eo size,pid,user,command --sort -size |
awk '{ hr=$1/1024/1024 ; printf("%13.2f GIGA ",hr) }
     { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' |
cut -d "" -f2 | cut -d "-" -f1 | more

        58.13 GIGA java
        38.39 GIGA /home/mc/lok_agent/mc.pl
        36.00 GIGA /usr/lib/jvm/java
        23.99 GIGA /usr/jdk64/jdk1.8.0_112/bin/java
        19.42 GIGA /usr/jdk64/jdk1.8.0_112/bin/java
        19.39 GIGA /usr/jdk64/jdk1.8.0_112/bin/java
        19.37 GIGA /usr/jdk64/jdk1.8.0_112/bin/java
        17.42 GIGA java
        15.43 GIGA /usr/jdk64/jdk1.8.0_112/bin/java
        15.42 GIGA /usr/jdk64/jdk1.8.0_112/bin/java
        15.23 GIGA /usr/jdk64/jdk1.8.0_112/bin/java
        10.18 GIGA /usr/jdk64/jdk1.8.0_112/bin/java
         7.22 GIGA /usr/jdk64/jdk1.8.0_112/bin/java
         7.02 GIGA /usr/jdk64/jdk1.8.0_112/bin/java
         5.71 GIGA /usr/jdk64/jdk1.8.0_112/bin/java
         5.57 GIGA /usr/bin/gnome
.
.
.

Until now the sum of above commands is much more then 200G

But when I run free -g I get used 168

free -g
              total        used        free      shared  buff/cache   available
Mem:            251         168           2           0          81          82
Swap:            15          11           4

So something with my approach isn’t right

ps -eo size,pid,user,command --sort -size |     awk '{ hr=$1/1024/1024 ; printf("%13.2f GIGA ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' |    cut -d "" -f2 | cut -d "-" -f1 |more

any advice what is wrong with my syntax ?

2
  • 2
    I think you want rss, not size, check the man page. And it's gibi, not giga.
    – Bib
    Aug 1, 2021 at 20:02
  • See also ps --no-headers -eo rss,pid,user,args --sort -rss | numfmt --from-unit=1024 --format=%13.2f --to=iec-i --suffix=B Aug 4, 2021 at 5:30

1 Answer 1

2

There are different ways of measuring memory used in processes. The problem is processes share memory (think of two processes using the same shared library, it's in-memory once) and you can have resident (on the RAM chips), swapped (on disk) or virtual (either/both).

Using rss instead of size will eliminate the swapped/virtual issue but not the shared.

The (probably) next release of procps will have ps and top making available PSS and USS fields, for proportional/unique segment size. These either allocate (e.g. 3 processes using a shared library get 1/3rd the size of that library) or ignore the shared part.

1
  • See also the memstat command which gives some more information as to how the memory is shared. Aug 4, 2021 at 5:32

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.