Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 1219  / 1 Year ago, sat, february 11, 2023, 8:40:56

I typed the free command to get the memory usage as follows :



free -m 


output:



enter image description here



I want to use this command to get the same info but for all users for example :



enter image description here



I used this command .. because it easy for me .. to store its output in a variables in a bash scrip ...


More From » 12.04

 Answers
1

free is already based on the system-wide memory usage.



If you want something on a per-user basis, you could try something like:



ps aux | awk 'NR>2{arr[$1]+=$6}END{for(i in arr) print i,arr[i]}'


As a quick explanation of what the awk does:




  • Strips off the first line

  • Iterates through each line and creates an array of every given username. For each of those it adds the sixth column from ps aux (resident set size) and adds them up.

  • After that it just iterates through the array keys to print the content.


[#27008] Monday, February 13, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rtbrbab

Total Points: 461
Total Questions: 126
Total Answers: 117

Location: Saudi Arabia
Member since Fri, Jul 1, 2022
2 Years ago
;