Shell script used to view linux memory usage

Source: Internet
Author: User

In linux, the/proc/$ PID/status file provides the usage of the Process resources (memory, stack, semaphore, sub-parent process, although linux provides a lot of memory viewing commands, they all look at the overall usage and cannot view the memory usage of a single process.

This script is provided in this Article. You can view the VmRSS field in the status file to view the memory usage of the system or process. If you need it, refer to it.

Copy codeThe Code is as follows :#! /Bin/bash

Echo-n "PidName">/root/script/pid. f
Echo "MeMery">/root/script/pid. f

PIDPATH =/proc/
TOTLE = 0
Cd $ PIDPATH
DOC = 'LS'
For DOCNAME in $ DOC
Do
If [-d $ DOCNAME]; then
Cd $ DOCNAME
If [-f status]; then
MEMERY = 'grep VmRSS status | awk-F': ''{print $2} '| awk' {print $1 }''
PIDNAME = 'grep Name status | awk-F': ''{print $2 }''
If [$ MEMERY]; then
Echo-n $ PIDNAME>/root/script/pid. f
Echo-n "">/root/script/pid. f
Echo $ MEMERY>/root/script/pid. f
TOTLE = 'expr $ TOTLE + $ MEMERY'
Cd ..
Else
Cd ..
Fi
Else
Cd ..
Fi
Fi
Done
TOTLE = 'expr $ TOTLE/100'
Echo "totle userd: $ totle mb">/root/script/pid. f
Cat/root/script/pid. f

Related Article

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.