How can I get the memory of one process in Linux

Possible duplicate:
Linux: how to measure the actual memory usage of an application or process?

Why I use the "top" in Linux to show my memory of one process, I understand that the process storage only increases and does not decrease, except that I close the whole process. I do not know why, although I use "free" only for "malloc". How can I get the correct actual REAL-TIME storage of my process? thank you all.

+3
source share
5 answers

The short answer is that in a modern operating system it is very difficult.

, () ed, , . ()

SO. .

+4

pid, , "ps aux", "ps ax", :

cat /proc/<PID>/status

, .

+7

. (. MMAP_THRESHOLD malloc(3)), , , glibc mmap(2) MAP_ANONYMOUS ; free(3) , glibc , .

MMAP_THRESHOLD , mallopt(3), .

, , free(3) , . , - .

+1

, .

, sarnold, free() malloc() - . ...

, void *sbrk(intptr_t increment); 0 - - , . , glib brk(), .

0

pmap id:

    1:   init [3]

001c3000 100K r-x--/lib/ld-2.5.so

001dc000 4K r-x--/lib/ld-2.5.so

001dd000 4K rwx--/lib/ld-2.5.so

001e0000 1256K r-x--/lib/libc-2.5.so

0031a000 8K rx - / lib / libc-2.5.so

0031c000 4K rwx - / lib / libc-2.5.so

0031d000 12K rwx-- [anon]

0034b000 8K rx - / lib / libdl-2.5.so

0034d000 4K rx - / lib / libdl-2.5.so

0034e000 4K rwx - / lib / libdl-2.5.so

006f2000 236K rx - / lib / libsepol.so.1

0072d000 4K rwx - / lib / libsepol.so.1

0072e000 40K rwx-- [anon]

0073a000 84K rx - / lib / libselinux.so.1

0074f000 8K rwx - / lib / libselinux.so.1

00fff000 4K rx-- [anon]

08048000 32K rx - / sbin / init

08050000 4K rw --- / sbin / init

09c0f000 132K rw --- [anon]

b7fed000 8K rw --- [anon]

bfd87000 84K rw --- [stack]

total 2040K

0
source

All Articles