[CENTOS] Check memory usage

TL;DR

Please download "memory.sh" from github and use it. After executing the command, a file called "memory_size.txt" will be generated. From there you can see which process is using how much. It is sorted in descending order of usage.

command

./memory.sh

Operation check environment

OS : RHEL/CentOS 7.*

Shell script commentary

I will omit the parts that are not important.

Get memory information from the status file of all processes

# get memory data
for pid in $(grep VmSize /proc/*/status | cut -d/ -f3) ;do
name=$(grep Name /proc/$pid/status)
memorysize=$(grep VmSize /proc/$pid/status)
echo "-$name/PID:$pid/$memorysize"; echo
done

Format and sort the acquired data

# shaping information
sed -i -e '/^$/d' -e 's/\t//g' -e 's/ //g' $temp
sed -i '/^grep/d' $temp 

# sort informaiton
sed "s/kB//g" $temp |sort -r -n -k 4 -t : > $output

Confirmation of acquired data

As described in TL; DR, A file called memory_size.txt will be created in the same directory, so please check that.

How to check the acquired data

/ Is the delimiter from the left

Process name, process ID, memory usage (KB)

It has become.

-Name:sshd/PID:20073/VmSize:112920

Recommended Posts

Check memory usage
Check for memory leaks in Python
When looking at memory usage in Python 3
How to reduce GPU memory usage with Keras