Shell script for viewing Linux memory usage

Source: Internet
Author: User
Tags memory usage

In Linux, the/proc/$PID/status file provides the usage of the process resources (memory, stack, semaphore, child parent process), although Linux provides a lot of commands to view memory, but it's all about the overall usage and cannot view the memory usage of a single process.

This article provides you with this script, by looking at the Vmrss field in the status file to see the memory of the system or process used, the need for a friend may refer to.

Copy code:

#! /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

Todo

If [-D $DOCNAME]; Then

CD $DOCNAME

If [F Status];then

Memery= ' grep vmrss status | Awk-f ': ' {print $} ' | awk ' {print '} '

Pidname= ' grep Name status | Awk-f ': ' {print $} '

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/1024 '

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.