Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to check for processes with high CPU/ memory consumption

Shulou Source: shulou.com Published: 2022-06-01 05:25:12 10月01日 Update

Editor to share with you how to check the process of high CPU/ memory consumption, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

What is the ps command

Ps is a process status processes status that displays information about active / running processes on the system.

It provides a snapshot of the current process as well as details, such as user name, user ID, CPU usage, memory usage, process start date and time, and so on.

1) check how long the Bash script with high CPU consumption has been running on Linux

This script will help you determine how long the high CPU consumption process has been running on Linux.

# vi / opt/scripts/long-running-cpu-proc.sh #! / bin/bashps-eo pid,user,ppid,%mem,%cpu Cmd-- sort=-%cpu | head | tail-n + 2 | awk'{print $1}'> / tmp/long-running-processes.txtecho "-" echo "UName PID CMD Process_Running_Time" echo "- -- "for userid in `cat / tmp/long-running- processes.txt`dousername = $(ps-u-p $userid | tail-1 | awk'{print $1}') pruntime=$ (ps-p $userid-o etime | tail-1) ocmd=$ (ps-p $userid | tail-1 | awk'{print $4}') echo" $username $userid $ocmd $pruntime "done | column-techo"-- -"

Set executable Linux file permissions to long-running-cpu-proc.sh.

# chmod + x / opt/scripts/long-running-cpu-proc.sh

When you run this script, you will get output similar to the following:

# sh / opt/scripts/long-running-cpu-proc.sh-UName PID CMD Process_Running_Time-- -daygeek 5214 Web 01:18:48daygeek 5748 Web 01:08:20daygeek 8043 inkscape 22:11daygeek 5269 Web 01:18:31daygeek 1712 Web 10:44:50daygeek 5335 RDD 01:17:54daygeek 1639 firefox 10:44:51daygeek 7793 nautilus 24:14daygeek 6301 Web 57 -- 2) check how long the high memory consumption process has been running Bash scripts on Linux

This script will help you determine how long the maximum memory consumption process has been running on Linux.

# sh / opt/scripts/long-running-memory-proc.sh #! / bin/bashps-eo pid,user,ppid,%mem,%cpu Cmd-- sort=-%mem | head | tail-n + 2 | awk'{print $1}'> / tmp/long-running-processes-1.txtecho "-" echo "UName PID CMD Process_Running_Time" echo "- -- "for userid in `cat / tmp/long-running-processes- 1.txt`dousername = $(ps-u-p $userid | tail-1 | awk'{print $1}') pruntime=$ (ps-p $userid-o etime | tail-1) ocmd=$ (ps-p $userid | tail-1 | awk'{print $4}') echo" $username $userid $ocmd $pruntime "done | column-techo"- -"

Set executable Linux file permissions to long-running-memory-proc.sh.

# chmod + x / opt/scripts/long-running-memory-proc.sh

When you run this script, you will get output similar to the following:

# sh / opt/scripts/long-running-memory-proc.sh-UName PID CMD Process_Running_Time-- -daygeek 1639 firefox 10:44:56daygeek 2997 Web 10:39:54daygeek 5269 Web 01:18:37daygeek 1712 Web 10:44:55daygeek 8043 inkscape 22:17daygeek 5214 Web 01:18:54daygeek 1898 Web 10:44:48daygeek 1129 Xorg 10:45:07daygeek 6301 Web 57 Suzhou 45- -- these are all the contents of the article "how to check processes with high CPU/ memory consumption" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Processes runs consumes scripts memory time checks articles help usage information content files permissions users output maximum not much commands most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information Linux OPPO Reno Docker