Shell exercises to count memory usage

Source: Internet
Author: User
Tags memory usage


Demand:

Write a script that calculates the amount of memory that is consumed by all processes in the Linux system. (hint, use PS or TOP command)

#!/bin/bashtime= ' date +%y-%m-%d-%h:%m:%s ' # #方法一s =0for m in  ' ps aux |awk  ' { print $6} '  |grep -v  ' RSS ' Do ((s+= $m)) doneecho  "$time All processes memory-intensive and for   $s  k "  echo  "==========================" # #方法二sum =0for q in  ' ps aux |awk  ' { print $6} '  |grep -v  ' RSS ' dosum=$[$sum + $q]doneecho  "$time All processes consume memory and are   $sum  k "       echo " ======================== " # #方法三top  -bn1 | sed  ' 1,7 ' d >top.txtecho  "$time all processes that occupy memory and for   ' awk  ' {(zh=zh+$6)}; end {print  zh} '  top.txt '  k "echo " ========================= "# #方法四n = ' top -bn1 |sed  ' 1,7 ' d |awk  ' {(su=su+$6)}; END {PRINT SU} ' echo  ' $time all processes that occupy memory and for   $n  k "echo " ========================= "# # Method Five d= ' ps aux |grep -v  ' rss tty '  |awk  ' {(sum=sum+$6)}; End&nbSp {print sum} ' echo  ' $time All processes are memory-intensive and   $d  k  "






Shell exercises to count memory usage

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.