1 编写脚本实现传入进程pid,查看对应进程/proc下的CPU、内存指标。
#!/bin/bash
COLOR_RED_START="[1;31m"
COLOR_RED_END="[0m"
read -p "Please input the PID to check CPU&MEM infomation:" pid
checkPid=`ps aux | awk '{print $2}' | grep -w "$pid"`
if [ ! $checkPid ];then
echo "The pid '$pid' does not exits, please make sure and input a correct pid. "
else
echo -e "\033${COLOR_RED_START}The MEM info is:\033${COLOR_RED_END}\n`sed -nr "/^Vm*/p" /proc/$pid/status`"
echo -e "\033${COLOR_RED_START}The CPU info is:\033${COLOR_RED_END}\n`sed -nr "/^Cpu*/p" /proc/$pid/status`"
echo -e "\033${COLOR_RED_START}The MEM PID_$pid uses is:\033${COLOR_RED_END} `ps -p $pid -o %mem | sed -n '2p'`"
echo -e "\033${COLOR_RED_START}The CPU PID_$pid uses is:\033${COLOR_R