linux process memory

How Does a Process Use Memory?

When a process starts, the operating system allocates the amount of memory the process requires to run. Each process has four memory segments for executable code and data. The "code" segment contains the executable instructions. The "data" segment contains static and global variables. The "stack" contains local variables. The "heap" contains dynamically allocated objects. Processes may use shared libraries. Shared libraries are only loaded into memory once, and all processes using a particular shared library will use that copy.
What Memory Statistics Does Linux Report?

Virtual memory is the total amount of the address space reserved by the operating system to the process for its code, data and stack. The virtual memory size reported by Linux includes all the code, data and stack space reserved for use by a process, on both physical memory and swap space. This value includes space used by all shared libraries used by the process. The implication of this is that shared libraries count in full towards the size of a given process.

The resident memory size of a process reported by Linux includes only the amount of physical memory the process and the shared libraries it references are using at a given time. Segments moved to swap space are not included. Like with virtual memory size, resident memory size includes the space used by shared libraries.
Viewing a Simple Process Snapshot with ps

The ps utility provides a snapshot of processes running on the system, reporting the virtual and resident memory size, CPU and memory percentages, and a wide variety of other information. To examine a single process, use the following options to ps, including vsz for the virtual memory size, and rss for the resident memory size. For example,

ps p 3746 o pid,rss,vsz,comm

outputs for process 3746:

PID RSS VSZ COMMAND
3746 14444 351216 httpd2
Monitoring Processes with top
The top utility customized to display process memory usage. Deborah Lee Soltesz

The top utility provides a live view of system performance. To monitor one or more specific processes with top, use the --p option to provide a list of process IDs. For example:

top -p 3746,6100,28753,23176,25544

After launching top, hit the command key "f" to access the column selection screen. Turn on the display for the PID, VIRT, RES, SHR, SWAP, CODE, DATA, and COMMAND columns. As illustrated in the screen shot, the display now shows the following memory statistics:

VIRT: Virtual memory size
RES: Resident memory size
SHR: Shared memory size
SWAP: Swapped size
CODE: Code size in physical memory
DATA: Data plus stack size in physical memory
Peeking in /proc

Detailed status and process memory usage information can be found in /proc/<pid>/status and /proc/<pid>/smaps. A variety of information is contained in /proc/<pid>/status, including these memory statistics:

VmPeak: Peak virtual memory size
VmSize: Virtual memory
VmData: Data segment size
VmStk: Stack size
VmExe: Executable segment size
VmLib: Library code size

/proc/<pid>/smaps provides a very detailed view of a process' memory usages, broken down by mapping for code, stack, heap and each shared library. The complete output of smaps is rather lengthy and difficult to digest. You can use the Linux:Smaps Perl module to parse and process the smaps file.


Read more: How Much Linux Memory is Used by a Process? | eHow.com http://www.ehow.com/about_5497321_much-linux-memory-used-process.html#ixzz2ABgUaeIA
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值