View the running space of a Linux Process

Source: Internet
Author: User

In Linux, how does one check the memory usage of a service process when a service program is started? Here, we will briefly list how the following Linux commands are viewed and what the information is.

1. First of all, you need to find all the process IDs you want to view. There are many methods. Here I will introduce my common methods:

Run the command PS-efView the information of all processes in the current system, and find the process in which you are connected. When there are many processes in the system, it is troublesome. Add the grep command to select the process.

root@dremi-desktop:~# ps -efUID        PID  PPID  C STIME TTY          TIME CMDroot         1     0  0 11:41 ?        00:00:00 /sbin/initroot         2     0  0 11:41 ?        00:00:00 [kthreadd]root         3     2  0 11:41 ?        00:00:00 [migration/0]root         4     2  0 11:41 ?        00:00:00 [ksoftirqd/0]root         5     2  0 11:41 ?        00:00:00 [watchdog/0]root         6     2  0 11:41 ?        00:00:00 [events/0]root         7     2  0 11:41 ?        00:00:00 [khelper]root        42     2  0 11:41 ?        00:00:00 [kblockd/0]

For example, root @ dremi-desktop :~ # Ps-Ef | grep bash

dremi     5993  5990  0 11:44 pts/0    00:00:00 bashroot      6270  6266  0 11:56 pts/1    00:00:00 -bashroot      6379  6270  0 12:00 pts/1    00:00:00 grep bashroot@dremi-desktop:~#

If you know the full name of the process, use this command to facilitate the pidof process name.

root@dremi-desktop:~# pidof bash5993root@dremi-desktop:~#

2. Find the entry and exit ID, and view the running space of the process directly. You can check the/proc/Pid/maps file or print it between pmap commands.

root@dremi-desktop:~# cat /proc/5993/maps08048000-080ef000 r-xp 00000000 08:01 1605637    /bin/bash080ef000-080f5000 rw-p 000a6000 08:01 1605637    /bin/bash080f5000-08312000 rw-p 080f5000 00:00 0          [heap]b7bd2000-b7bdc000 r-xp 00000000 08:01 17500      /lib/tls/i686/cmov/libnss_files-2.11.1.sob7bdc000-b7bdd000 r--p 00009000 08:01 17500      /lib/tls/i686/cmov/libnss_files-2.11.1.sob7bdd000-b7bde000 rw-p 0000a000 08:01 17500      /lib/tls/i686/cmov/libnss_files-2.11.1.sob7bde000-b7be6000 r-xp 00000000 08:01 17504      /lib/tls/i686/cmov/libnss_nis-2.11.1.sob7be6000-b7be7000 r--p 00007000 08:01 17504      /lib/tls/i686/cmov/libnss_nis-2.11.1.sob7be7000-b7be8000 rw-p 00008000 08:01 17504      /lib/tls/i686/cmov/libnss_nis-2.11.1.sob7be8000-b7bfb000 r-xp 00000000 08:01 17494      /lib/tls/i686/cmov/libnsl-2.11.1.sob7bfb000-b7bfc000 r--p 00012000 08:01 17494      /lib/tls/i686/cmov/libnsl-2.11.1.sob7bfc000-b7bfd000 rw-p 00013000 08:01 17494      /lib/tls/i686/cmov/libnsl-2.11.1.soroot@dremi-desktop:~# pmap 59935993:   bash08048000    668K r-x--  /bin/bash080ef000     24K rw---  /bin/bash080f5000   2164K rw---    [ anon ]b7bd2000     40K r-x--  /lib/tls/i686/cmov/libnss_files-2.11.1.sob7bdc000      4K r----  /lib/tls/i686/cmov/libnss_files-2.11.1.sob7bdd000      4K rw---  /lib/tls/i686/cmov/libnss_files-2.11.1.sob7bde000     32K r-x--  /lib/tls/i686/cmov/libnss_nis-2.11.1.sob7be6000      4K r----  /lib/tls/i686/cmov/libnss_nis-2.11.1.sob7be7000      4K rw---  /lib/tls/i686/cmov/libnss_nis-2.11.1.sob7be8000     76K r-x--  /lib/tls/i686/cmov/libnsl-2.11.1.sob7bfb000      4K r----  /lib/tls/i686/cmov/libnsl-2.11.1.sob7bfc000      4K rw---  /lib/tls/i686/cmov/libnsl-2.11.1.so

The meaning of the result shown above is described below,

I usually use these two methods:

root@dremi-desktop:~# cat /proc/`pidof bash`/maps08048000-080ef000 r-xp 00000000 08:01 1605637    /bin/bash080ef000-080f5000 rw-p 000a6000 08:01 1605637    /bin/bash080f5000-08312000 rw-p 080f5000 00:00 0          [heap]b7bd2000-b7bdc000 r-xp 00000000 08:01 17500      /lib/tls/i686/cmov/libnss_files-2.11.1.sob7bdc000-b7bdd000 r--p 00009000 08:01 17500      /lib/tls/i686/cmov/libnss_files-2.11.1.sob7bdd000-b7bde000 rw-p 0000a000 08:01 17500      /lib/tls/i686/cmov/libnss_files-2.11.1.soroot@dremi-desktop:~#  pmap `pidof bash`599308048000    668K r-x--  /bin/bash080ef000     24K rw---  /bin/bash080f5000   2164K rw---    [ anon ]b7bd2000     40K r-x--  /lib/tls/i686/cmov/libnss_files-2.11.1.sob7bdc000      4K r----  /lib/tls/i686/cmov/libnss_files-2.11.1.so

3. The displayed information indicates the meaning:

Each interval has four attributes:
RIndicates that data can be read.
WIndicates that it can be modified.
XIndicates that the task can be executed.
P/SIndicates whether the memory is shared.
Memory interval with file name, attribute:R-PIndicates thatRodata.
Memory interval with file name, attribute:RW-PIndicates thatBSS and Data 
Memory interval with file name, attribute:R-XPIndicates thatTextData.
Memory interval without file name, indicating to useMMAPThe mapped anonymous space.
The file name is[Stack]The memory range of is stack.
The file name is [Heap]The memory range of is heap.

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.