Script to count the memory usage size of a process

Source: Internet
Author: User

#!/bin/bashmemlist= ' PS auxf--width=1000 |grep $1|grep-v grep|awk ' {print $6} '; totalmem=0for mem in $memlist; Do let "totalmem= $totalMem +mem" Doneecho $totalMem

$ $ represents the process name, which is the parameter given by the script. It is also specified in the item on the Zabbix.


The script above can be simplified:

#!/bin/bashmem= ' PS auxf--width=1000 |grep $1|grep-v grep|awk ' {sum+=$6}end{print sum} ' echo $mem


PS aux command detailed

[[email protected] scripts]# ps auxf --width=1000|moreuser         PID %CPU %MEM    VSZ   RSS TTY       STAT START   TIME COMMANDroot           2  0.0  0.0      0      0 ?        s    jun29    0:00 [kthreadd]root          3   0.0  0.0      0     0 ?         s    jun29   0:00  \_  [migration/0]root          4  0.0   0.0   &Nbsp;  0     0 ?        s     Jun29   0:00  \_ [ksoftirqd/0]root           5  0.0  0.0      0      0 ?        S     Jun29   0:00  \_ [stopper/0]root           6  0.0  0.0      0      0 ?        S    Jun29    0:00  \_ [watchdog/0]root          7   0.0  0.0      0     0 ?         s    jun29   0:31  \_ [events/0]root           8  0.0  0.0       0     0 ?        S     Jun29   0:00  \_ [events/0]root           9  0.0  0.0      0      0 ?        S    Jun29    0:00  \_ [events_long/0]root         10   0.0  0.0      0     0 ?         S    Jun29   0:00   \_ [events_power_ef]root         11  0.0  0.0       0     0 ?        s     Jun29   0:00  \_ [cgroup]root          12  0.0  0.0      0      0 ?        s    jun29    0:00  \_ [khelper]root          13  0.0  0.0      0     0 ?         S    Jun29   0:00   \_ [netns]root         14  0.0   0.0      0     0 ?        s     Jun29   0:00  \_ [async/mgr]root          15  0.0  0.0      0      0 ?        S    Jun29    0:00  \_ [pm]root         16  0.0   0.0      0     0 ?         s    jun29   0:00  \_ [sync_supers] root         17  0.0  0.0       0     0 ?        s     jun29   0:00  \_ [bdi-default]root          18  0.0  0.0      0      0 ?        S    Jun29    0:00  \_ [kintegrityd/0]root         19   0.0  0.0      0     0 ?         s    jun29   0:13  \_  [kblockd/0]root         20  0.0  0.0       0     0 ?         S    Jun29   0:00  \_ [kacpid]root          21  0.0  0.0      0     0  ?        s    jun29   0:00   \_ [kacpi_notify]root         22  0.0   0.0      0     0 ?         s    jun29   0:00  \_ [kacpi_ hotplug]root         23  0.0  0.0       0     0 ?         S    Jun29   0:00  \_ [ata_aux]root          24  0.0  0.0      0      0 ?         S    Jun29   0:00   \_ [ata_sff/0]root         25  0.0   0.0      0     0 ?         s    jun29   0:00  \_ [ksuspend_usbd ]

USER: The owner of the process;
PID: The ID of the process;
PPID: Parent process;
%cpu: Percentage of CPU consumed by the process;
%MEM: The percentage of memory occupied;
NI: The nice value of the process, large value, indicating less CPU time;
VSZ: The amount of virtual memory used by the process (KB);
RSS: The amount of fixed memory (KB) that the process occupies (the number of pages residing in);
TTY: The process is run on that end (the terminal position of the landing), and if it is not relevant to the end, it is displayed (? )。 If the pts/0, it means that the network connects the host
Wchan: If the previous process is in progress, if-that means it is in progress;
Start: The start time of the process being touched;
Time: The process actually uses the CPU to run the line;
Command: The name and parameters of the commands;


Stat Common Status:

D a dormant state (usually IO process) that cannot be interrupted;
R is running can be in the queue can be too line;
S is in a dormant state;
T stop or be traced;
W enters memory swap (invalid starting from kernel 2.6);
X dead process (basic rarely seen);
Z Zombie process;
< high-priority processes
N Low-priority processes
L Some pages are locked into memory;
Leader of the S-process (under it there are sub-processes);
L multi-process (using Clone_thread, similar to NPTL pthreads);
+ Process Group located in the background;



Reference: http://blog.csdn.net/hanner_cheung/article/details/6081440

This article is from the "Zengestudy" blog, make sure to keep this source http://zengestudy.blog.51cto.com/1702365/1833505

Script to count the memory usage size of a process

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.