Monday, 13 January 2020

Check which process taking high memory & cpu ?

 # ps axo rss,comm,pid | awk '{ proc_list[$2]++; proc_list[$2 "," 1] += $1; } END { for (proc in proc_list) { printf("%d\t%s\n", proc_list[proc "," 1],proc); }}' | sort -n | tail -n 10 | sort -rn | awk '{$1/=1024;printf "%.0fMB\t",$1}{print $2}'

# ps aux --sort=-%mem | awk 'NR<=10{print $0}'
# ps aux |grep nginx |awk '{sum=sum+$6}; END {print sum/1024 " MB"}'

[ Check Top Processes sorted by RAM or CPU Usage in Linux ]
# ps -eo pid,ppid,user,cmd,%mem,%cpu --sort=-%mem | head
# ps -eo pid,ppid,user,cmd,%mem,%cpu --sort=-%cpu | head

[ php-fpm process (memory utilization) ]
# ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"Mb") }'

[ print Process Tree ]
# ps -e --forest | grep php-fpm
[Print Process Threads]
# ps -fL -C mysqld
# ps -fL -C httpd
# ps -fL -C php-fpm

[ custom output format showing process ID, Parent Process ID,file system group, nice value, start time and elapsed time of a process ]
# ps -eo pid,ppid,fgroup,user,cmd,ni,lstart,etime
# ps -eo pid,ppid,fgroup,user,cmd,ni,lstart,etime | grep httpd
# ps -eo pid,ppid,fgroup,user,cmd,ni,lstart,etime | grep php-fpm

[ Check execution time of a process ]
# ps -eo pid,comm,etime,user | grep httpd
# ps -eo pid,comm,etime,user | grep php-fpm
# ps -eo comm,etime,user | grep mysqld

[ find the PID of the unresponsive process or application and kill them ]
# ps -A | grep -i stress
# kill -9 2342 5632

[ monitor Real-time Process Monitoring Using Watch Utility as below ]
# watch -n 1 'ps -eo pid,ppid,user,cmd,%mem,%cpu --sort=-%mem | head'

No comments: