随意写的脚本。查看系统中占用内存最多的应用
#############################################################
#!/bin/bash
>pidfile
>mem.txt
>memmaxPID.txt
ps -ef |grep -v init | awk '{print $2}' >pidfile
for PID in $(cat pidfile)
do
echo "${PID} $(cat /proc/${PID}/smaps | grep -i rss | awk '{s+=$2}END{print s}')">>mem.txt
done
memmax=$(cat mem.txt | grep $(cat mem.txt | awk '{for(i=1;i<=NR;i++) if($2>s) s=$2;}END{print s}'))
echo $memmax |awk '{print $1}'>memmaxPID.txt
memmaxproc=$(ps -ef | grep $(cat memmaxPID.txt) | grep -v grep | sed -n 's/^\(.*\)\([[:space:]]\+\)\([[:digit:]]\+\):\([[:digit:]]\+\):\([[:digit:]]\+\)\([[:space:]]\+\)\(.*\)$/\7/p')
echo "The MAX memory usage PID is $(cat memmaxPID.txt)"
echo "The MAX memory usage proc is $memmaxproc"
echo $memmax | awk '{printf("The MAX memory usage is %fMB\n",$2/1024)}'
rm -rf pidfile mem.txt memmaxPID.txt