When managing a multi-user Linux system, tracking individual memory consumption becomes crucial for resource allocation, troubleshooting, and performance optimization. Unlike Windows Task Manager, Linux requires command-line tools to break down memory usage by user.
The most effective approach combines several standard Linux utilities:
# Basic process listing with memory info
ps -eo user,pid,%mem,rss,command --sort=-%mem | head -n 20
For comprehensive per-user statistics, use this awk-powered solution:
ps -eo user,rss | awk 'NR>1 {arr[$1]+=$2} END {for (i in arr) print i,arr[i]}' | \
sort -nk2 -r | awk '{printf "%-20s %8.2f MB\n", $1, $2/1024}'
Combine with watch for continuous monitoring:
watch -n 5 "ps -eo user,rss | awk 'NR>1 {arr[\$1]+=\$2} END {for (i in arr) print i,arr[i]}' | \
sort -nk2 -r | awk '{printf \"%-20s %8.2f MB\\n\", \$1, \$2/1024}'"
For systems with smem installed (sudo apt-get install smem):
smem -u -k -t -p
Create a cron job for historical tracking:
*/15 * * * * root ps -eo user,rss | awk 'NR>1 {arr[$1]+=$2} END {for (i in arr) print strftime(\"%Y-%m-%d %H:%M\"),i,arr[i]/1024}' >> /var/log/user_mem.log
Remember these key points when analyzing output:
- RSS (Resident Set Size) shows physical memory used
- Values are typically in KB (divide by 1024 for MB)
- Shared libraries may cause apparent overcounting
When identifying memory-intensive users:
# Show top processes for a specific user
pgrep -u username | xargs ps -o pid,user,%mem,command -p | sort -nk3 -r | head
When managing multi-user Linux systems, tracking individual memory consumption becomes crucial for system administrators and developers. Unlike Windows Task Manager, Linux requires more technical approaches to isolate memory usage per active user session.
The most effective method combines ps
with awk
for quick analysis:
ps -o user,rss,comm -u $(who | awk '{print $1}' | sort -u) | \\
awk 'NR>1 {arr[$1]+=$2} END {for (i in arr) print i,arr[i]/1024"MB"}'
For more comprehensive reporting, install the smem
tool:
sudo apt install smem # Debian/Ubuntu
sudo yum install smem # RHEL/CentOS
Then generate per-user reports:
smem -u -k -t -p
For continuous monitoring, create this bash script (memtrack.sh
):
#!/bin/bash
while true; do
date >> /var/log/user_mem.log
ps -eo user,pid,rss,comm --sort -rss | \\
awk 'NR>1 {arr[$1]+=$3} END {for (i in arr) print i,arr[i]/1024"MB"}' >> /var/log/user_mem.log
sleep 300
done
Modern systems can leverage:
systemd-cgtop -m --order=memory
This provides real-time memory usage grouped by systemd slices, useful when users run services.
- Shared memory attribution requires special handling
- Containerized environments need additional flags
- For accurate accounting, consider using PAM limits
Developers can access low-level metrics through:
grep -i rss /proc/[0-9]*/status | \\
awk -F'/' '{print $3,$5}' | \\
while read pid mem; do \\
user=$(ps -o user= -p $pid); \\
echo $user $pid $mem; \\
done | sort