Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the memory of one process in Linux [duplicate]

Tags:

linux

unix

Possible Duplicate:
Linux: How to measure actual memory usage of an application or process?

Why I use 'top' in Linux to show my memory of one process,I get that the storage of the process do only increase and do not decrease except I close the all process.I don't know why,though I use 'free' only behind 'malloc'. How can I get the correct actual REAL-TIME storage of my process? thanks all.

like image 962
keyoflov Avatar asked May 02 '12 06:05

keyoflov


People also ask

How can you find how much memory a specific process consumes?

You can check memory of a process or a set of processes in human readable format (in KB or kilobytes) with pmap command. All you need is the PID of the processes you want to check memory usage of. As you can see, the total memory used by the process 917 is 516104 KB or kilobytes.

How do I monitor a single process in Linux?

The top Command. Usually, we can use the Linux built-in top command. This command displays a real-time view of a running system in the command prompt. If we want to have an idea of a single process, we can use the -p parameter.


3 Answers

find the pid, if its running as the same user, use "ps aux", otherwise use "ps ax", then execute this:

cat /proc/<PID>/status

this should be all u want to know.

like image 56
K1773R Avatar answered Nov 15 '22 17:11

K1773R


The short answer is that on a modern operating system this is very difficult.

Memory that is free()ed is not actually returned to the OS until the process terminates, so many cycles of allocating and freeing progressively bigger chunks of memory will cause the process to grow. (via)

This question has been already answered in more detail on another SO thread. You might find your answer there.

like image 31
Lee Hambley Avatar answered Nov 15 '22 17:11

Lee Hambley


Depending upon the size of your allocations, your memory may or may not be returned to the OS. If you're allocating large things (see MMAP_THRESHOLD in malloc(3)), things that take many pages of memory, glibc will use mmap(2)'s MAP_ANONYMOUS flag for the allocation; when you free(3) this object, glibc can return the page to the OS, and your memory usage will go down.

You can tune MMAP_THRESHOLD down using mallopt(3) if you wish.

If you have many smaller allocations, your memory may be fragmented enough that free(3) cannot actually free up an entire page that could be returned to the OS. You might have relatively little in use on a given page, but the entire page is still allocated against your process, and it replaces an entire page's worth of data from other processes.

like image 23
sarnold Avatar answered Nov 15 '22 17:11

sarnold