-
Notifications
You must be signed in to change notification settings - Fork 0
/
memproc.sh
executable file
·29 lines (21 loc) · 1.1 KB
/
memproc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
TYPE=("Rss" "Shared" "Private" "Swap" "Pss")
# Rss: resident memory usage, all memory the process uses, including all memory this process shares with other processes. It does not include swap;
# Shared: memory that this process shares with other processes;
# Private: private memory used by this process, you can look for memory leaks here;
# Swap: swap memory used by the process;
# Pss: Proportional Set Size, a good overall memory indicator. It is the Rss adjusted for sharing: if a process has 1MiB private and 20MiB shared between other 10 processes, Pss is 1 + 20/10 = 3MiB
PROCESS_NAME=$1
n=$2
i=0
for PID in `pidof ${PROCESS_NAME}`; do
PID_LIST[$i]=$PID
# echo $i ${PID_LIST[$i]}
i=$((i+1))
done
echo "Finding ${TYPE[$n]} type memory usage for ${PROCESS_NAME}"
echo " --- PID: ${PID_LIST[0]}"
MEM=$(echo 0 $(cat /proc/${PID_LIST[0]}/smaps | grep "${TYPE[$n]}" | awk '{print $2}' | sed s#^#+# ) | bc)
UNIT=$(cat /proc/${PID_LIST[0]}/smaps | grep "${TYPE[$n]}" | awk '{print $3}' | tail -1)
echo '*** ' ${MEM} ' ' ${UNIT} ' ***'
echo '*** ' `units -t "${MEM} ${UNIT}" GB` ' GB ***'