Thursday, February 22, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 1182  / 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
rtbrbab questions
Fri, May 5, 23, 14:22, 10 Months ago
Tue, Nov 16, 21, 14:41, 2 Years ago
Thu, Mar 23, 23, 20:47, 1 Year ago
Sat, Jun 18, 22, 21:36, 2 Years ago
;