Find memory, high CPU-intensive process scripts

Source: Internet
Author: User

#!/bin/bash

PS-E-O ' rsz,pid, ' | Sort-nrk1 | head-5 >/tmp/np.txt

PS-E-o ' pcpu,pid ' | Sort-nrk1 | head-5 >/tmp/up.txt


#查询内存使用情况

echo "========================================================================================================="

echo "==========================="

echo "Memory occupies the top five-bit app as:"

echo "==========================="

Echo-e ' \ n '

Cat/tmp/np.txt | While Read NLINE

Do

echo "app as:"

Ps-ef |grep ' echo $NLINE | awk ' {print $} ' | Grep-v "grep"

echo "takes up memory as (G):"

Npn1= ' echo $NLINE | awk ' {print '} '

npn2=1048576

awk ' begin{printf '%.2f\n ', ' $NPN 1 '/' $NPN 2 '} '

Echo-e ' \ n '

Done

echo "========================================================================================================="


#查询CPU使用率

Echo-e ' \ n '

echo "========================================================================================================="

echo "============================"

echo "CPU utilization top five apps are:"

echo "============================"

Cat/tmp/up.txt | While Read Uline

Do

echo "app as:"

Ps-ef |grep ' echo $ULINE | awk ' {print $} ' | Grep-v "grep"

echo "Cup usage is:"

echo $ULINE | awk ' {print '} '

Echo-e ' \ n '

Done

echo "========================================================================================================="



#查询内存和CPU使用率都较高的应用

Echo-e ' \ n '

echo "========================================================================================================="

echo "============================="

echo "Applications with high memory and CPU utilization:"

echo "============================="

Echo-e ' \ n '

Cat/tmp/np.txt | While Read Nuline

Do

If ["$ (Find/tmp/up.txt | Xargs grep ' echo $NULINE | awk ' {print $} ') '! = ' "];then

echo "app as:"

Ps-ef |grep ' echo $NULINE | awk ' {print $} ' | Grep-v "grep"

Echo-e ' \ n '

echo "takes up memory as (G):"

Npn1= ' echo $NULINE | awk ' {print '} '

npn2=1048576

awk ' begin{printf '%.2f\n ', ' $NPN 1 '/' $NPN 2 '} '

Echo-e ' \ n '

echo "Cup usage is:"

Find/tmp/up.txt| Xargs grep ' echo $NULINE | awk ' {print $} ' | awk ' {print '} '

Echo-e ' \ n '

Fi

Done

echo "========================================================================================================="


This article is from the "Operation and maintenance of the Road" blog, please be sure to keep this source http://lrtao2010.blog.51cto.com/10425744/1861450

Find memory, high CPU-intensive process scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.