Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check for processes with high CPU/ memory consumption

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 285

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report