LINUX Process memory usage command

Source: Internet
Author: User

In CentOS, we can use the top command to view cpu and memory usage in linux. Next I will give you an example to see if you need to know about it.

(1) top mission

The Code is as follows: Copy code

$ Top-u oracle

1. top Command

The Code is as follows: Copy code
Top-d 1-p pid [, pid...] // set it to delay 1 s. The default value is delay 3 s.

To Sort by memory usage, shift + m (Sort by memory usage)

(2) pmap

You can view the memory occupied by the process information based on the process. (You can view the process number in ps:

The Code is as follows: Copy code
$ Pmaps-d 14596

(3) ps
  
For example:

The Code is as follows: Copy code
$ Ps-e-o 'pid, comm, args, pcpu, rsz, vsz, stime, user, uid' where rsz is the actual memory
$ Ps-e-o 'pid, comm, args, pcpu, rsz, vsz, stime, user, uid' | grep oracle | sort-nrk5

Rsz is the actual memory, and the preceding example is sorted by memory, from large to small.

Static view of memory usage of a process

1. pmap command

The Code is as follows: Copy code
Pmap pid

2. ps command

The Code is as follows: Copy code
Ps aux | grep process_name

3. view the status file in the/proc/process_id/folder.

The Code is as follows: Copy code
Name: php
State: R (running)
SleepAVG: 0%
Tgid: 21574
Pid: 21574
PPid: 10005
TracerPid: 0
Uid: 1000 1000 1000 1000
Gid: 100 100 100 100
FDSize: 256.
Groups: 16 100
VmPeak: 161740 kB
VmSize: 161740 kB
VmLck: 0 kB
VmHWM: 107144 kB
VmRSS: 107144 kB
VmData: 106192 kB
VmStk: 84 kB
VmExe: 5588 kB
VmLib: 7884 kB
VmPTE: 268 kB
Threads: 1
SigQ: 0/69632
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000001000
SigCgt: 00000001818040a7
CapInh: 0000000000000000
Cappr: 0000000000000000
CapEff: 0000000000000000
Cpus_allowed: 00000000,00000000, 00000000,000 0000f
Mems_allowed: 1

Task virtual address space size VmSize
The physical memory size that the application is using VmRSS


To view the memory, we generally use the free command:

The Code is as follows: Copy code


[Root @ scs-2 tmp] # free
Total used free shared buffers cached
Mem: 3266180 3250004 16176 0 110652 2668236
-/+ Buffers/cache: 471116 2795064
Swap: 2048276 80160 1968116

The following is an explanation of these values:
Total: total physical memory size.
Used: used.
Free: available.
Shared: The total memory Shared by multiple processes.
Buffers/cached: disk cache size.
Row 3 (-/+ buffers/cached ):
Used: used.
Free: available.
The fourth line won't be explained much.
Difference: used/free of the second row (mem) differs from used/free of the third row (-/+ buffers/cache. The difference between the two is that from the perspective of usage, the first line is from the OS perspective, because for OS, buffers/cached is used, so its available memory is 16176KB, the memory used is kb, including the + buffers + cached used by the kernel (OS) + Application (X, oracle, etc.
The third line indicates that, from the application perspective, for applications, buffers/cached is equivalent to available, because buffer/cached is designed to improve file read performance, when the application needs to use the memory, buffer/cached will be quickly recycled.

Memory usage Measurement

Measure how much memory a process occupies. linux provides us with a very convenient method. The/proc Directory provides us with all the information, in fact, the top tool also obtains the corresponding information here.

The Code is as follows: Copy code

/Proc/meminfo memory usage information of the machine

/Proc/pid/maps pid is the process number and displays the virtual address occupied by the current process.

Memory occupied by/proc/pid/statm Process

[Root @ localhost ~] # Cat/proc/self/statm

654 57 44 0 0 334 0

Output description

CPU and CPU 0... The meaning of each parameter in each row (in the first behavior example) is:

Parameter description/proc // status

The Code is as follows: Copy code

Size (pages) task virtual address space Size VmSize/4

The size of the physical memory that the Resident (pages) application is using VmRSS/4

Shared (pages) Shared pages 0

Size of executable virtual memory owned by the Trs (pages) program VmExe/4

The size of the library that the Lrs (pages) is mapped to the virtual memory space of the task. VmLib/4

Drs (pages) Program Data Segment and user-state stack size (VmData + VmStk) 4

Dt (pages) 04

View available machine memory

The Code is as follows: Copy code

/Proc/28248/> free

Total used free shared buffers cached

Mem: 1023788 926400 97388 0 134668 503688

-/+ Buffers/cache: 288044 735744

Swap: 1959920 89608 1870312

When we run the free command to view the idle memory of the machine, we will find that the free value is very small. This is mainly because there is such an idea in linux, the memory does not need to be white, so it tries its best to cache and buffer some data for the next use. But in fact, these memories can also be used immediately.

So free memory = free + buffers + cached = total-used

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.