Skip to content

Instantly share code, notes, and snippets.

@PSJoshi
Last active August 5, 2022 06:16
Show Gist options
  • Save PSJoshi/2c49654ab375a5796869bdabaf2e2546 to your computer and use it in GitHub Desktop.
Save PSJoshi/2c49654ab375a5796869bdabaf2e2546 to your computer and use it in GitHub Desktop.
memory utilization per process
#!/bin/bash
# other interesting memory utilization scripts
# https://github.com/jhclark/memusg
# https://github.com/shovon8/sysmon/blob/master/sysmon
# https://gist.github.com/taoliu/1572440
mem_info=$(ps -o pid,user,%mem,command ax | grep -v PID | awk '/[0-9]*/{print $1 ":" $2 ":" $3 ":" $4}')
for i in $mem_info
do
process_pid=$(echo $i | cut -d: -f1)
user=$(echo $i | cut -d: -f2)
cmd=$(echo $i | cut -d: -f4)
mem_usage=$(pmap $process_pid | tail -n 1 | awk '/[0-9]/{print $2}')
echo "$process_pid" "$user" "$mem_usage" "$cmd"
done
# you can also use the following commands to get an idea:
# ps -eo pid,tid,class,rtprio,stat,vsz,rss,comm |sort -k 7 -r|more
# ps -eo pid,stat,vsz,rss,%mem |sort -k 5 -r |more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment