0

by the following command we can check which process is using most memory

as we can see the first field show in MB the used for each process

is it possible by awk to sum all the numbers and to get final used number in MB?

for example

24738.3 MB

the command to show all process and their used in MB ( memory )

ps aux  | awk '{print $6/1024 " MB\t\t" $01}'  | sort -n



4.74609 MB              postgres
5.01562 MB              postgres
5.19922 MB              postgres
5.3125 MB               postgres
5.33203 MB              postgres
5.35156 MB              postgres
5.43359 MB              postgres
5.53906 MB              WEPLO_qw
5.56641 MB              postgres
5.56641 MB              postgres
5.64062 MB              WEPLO_qw
5.65234 MB              postgres
5.68359 MB              postgres
5.75391 MB              postgres
5.97656 MB              postgres
6.33594 MB              postgres
6.55469 MB              postgres
6.57031 MB              postgres
6.60547 MB              postgres
6.63672 MB              postgres
7 MB            postgres
7.81641 MB              postgres
8.07812 MB              postgres
9.67578 MB              postgres
10.0234 MB              YTE
11.5156 MB              YTE
14.8828 MB              HTE_DS
15.2305 MB              hdfs
16.9297 MB              postgres
18.0781 MB              postgres
18.1172 MB              postgres
18.2812 MB              postgres
19.2695 MB              WEPLO_qw
21.1055 MB              postgres
21.1914 MB              postgres
21.6367 MB              postgres
21.9062 MB              postgres
23.5078 MB              postgres
24.4727 MB              polkitd
27.0938 MB              postgres
27.4375 MB              apache
28.0234 MB              apache
28.6445 MB              WEPLO_qw
29 MB           apache
30.4336 MB              apache
30.5664 MB              apache
32.4727 MB              apache
32.9023 MB              apache
50.1758 MB              WEPLO_qw
69.3398 MB              HTE_DS
72.7852 MB              HTE_DS
72.7891 MB              HTE_DS
72.7969 MB              HTE_DS
72.8008 MB              HTE_DS
72.8047 MB              HTE_DS
72.8125 MB              HTE_DS
72.8242 MB              HTE_DS
72.8281 MB              HTE_DS
72.832 MB               HTE_DS
72.8359 MB              HTE_DS
72.8438 MB              HTE_DS
72.8477 MB              HTE_DS
72.8516 MB              HTE_DS
72.8555 MB              HTE_DS
72.8594 MB              HTE_DS
72.8633 MB              HTE_DS
73.6602 MB              HTE_DS
74.418 MB               HTE_DS
75.2188 MB              HTE_DS
76.6641 MB              HTE_DS
76.75 MB                HTE_DS
78.4688 MB              HTE_DS
78.9492 MB              HTE_DS
85.2031 MB              WEPLO_qw
87.2344 MB              gdm
87.6367 MB              WEPLO_qw
100.711 MB              hdfs
114.703 MB              hdfs
132.32 MB               rabbitmq
191.383 MB              hdfs
204.285 MB              hdfs
298.152 MB              hdfs
360.168 MB              hdfs
360.402 MB              mapred
383.41 MB               Jko_+
387.973 MB              HTE_DS
412.961 MB              hdfs
499.574 MB              hdfs
562.395 MB              hdfs
689.383 MB              hdfs
802.691 MB              WEPLO_qw
886.816 MB              YTE
1017.73 MB              PLOT
1531.73 MB              zookeep+
1566.29 MB              HUT_OP
1739.48 MB              kafka
2275.65 MB              YTE
2738.92 MB              Grt-worker
4222.77 MB              anti-spam
2

Try this ,

If you want to add the total of the memory column from ps aux ,

ps aux  | awk '{print $6/1024}'  | xargs  | sed -E 's/ /+/g' | bc

This will give you the answer in MegaBytes.

On the other hand you can also check the memory statistics of the system using sar , free , vmstat, pidstat, or top. Just refer their man pages for more info.

1

Yes awk can add:

ps aux | awk '{t+=$6} END{print t/1024 "MB"}'
# or if you prefer to be explicit
ps aux | awk '{t=t+$6} END{print t/1024 "MB"}'
# or even more explicit (though awk does NOT need this)
ps aux | awk 'BEGIN{t=0} {t=t+$6} END{print t/1024 "MB"}'

It can do lots of other clever and sometimes powerful things also. But they remain closely held secrets because to find them you would have to look at the man page (or in prehistoric times, a thing called a "book" published by OReilly) and no one in the modern world can do that.

I don't see how computing the total memory used by all processes helps you "check which process is using the most memory" though.

If what you want is to display each item AND the total, awk can do that:

ps aux | awk '{print $6/1024 "\t\t" $1; t+=$6} END{print t/1024 "\t\tTOTAL"}'

If you wanted to sort the items in order of decreasing (or for that matter increasing) memory size, GNU awk (a common implementation but not the only one) can do that, but on Unix there is a sort program already available that is often more convenient.

  • your answer is very good but sai was the first solution , but any way thank you so much – yael Nov 29 '18 at 13:49

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.