Find out Memory Usage of each process in Linux

In this post, I have listed out some commands to show the Memory Usage of each process running.
Hope this will help you out to know memory utilization per process.
Also shared reference links where I found this commands.


1. Show the processes memory in megabytes and the process path.
Reference Link: https://superuser.com/

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

2. Total memory consumption by the current user.
Reference Link: https://superuser.com/

#echo "------------------------------------" && mem=0 && while read -r rss comm ; do mbs=$((rss/1024)); mem=$((mbs + mem)); echo $mbs"MB - $comm"; done <<< "$(ps -u $USER -wo rss=,comm= --sort -rss)" && echo "------------------------------------" && echo $mem"MB: Memory used by user '$USER'"

All user processes sorted by the highest memory usage in MB.

#ps -u $USER -wo rss=,comm= --sort -rss | while read -r rss comm ; do echo $((rss/1024))"MB -" $comm; done


3. Display Processes Sorted By Memory Usage in Linux.
Reference Link:https://www.shellhacks.com

#ps axo rss,comm,pid \
| awk '{ proc_list[$2]++; proc_list[$2 "," 1] += $1; } \
END { for (proc in proc_list) { printf("%d\t%s\n", \
proc_list[proc "," 1],proc); }}' | sort -n | tail -n 10 | sort -rn \
| awk '{$1/=1024;printf "%.0fMB\t",$1}{print $2}'

4. Top 10 processes sorted by memory usage.
Reference Link: https://www.linuxquestions.org/

#ps -eo rss,pid,user,comm | sort -rn | head -10 | awk '{ hr[1024**2]="GB"; hr[1024]="MB";
 for (x=1024**3; x>=1024; x/=1024) {
 if ($1>=x) { printf ("%-6.2f %s ", $1/x, hr[x]); break }
 } } { printf ("%-6s %-10s ", $2, $3) }
 { for ( x=4 ; x<=NF ; x++ ) { printf ("%s ",$x) } print ("\n") }'

No comments:

Post a Comment