0

There are commands such as top, ps, pmap (and others) that show how much memory is used by a process, but they only show the total memory.

Using the free -g command output we see total, used, shared, buffers and cached:

             total       used       free     shared    buffers     cached
Mem:           126         86         39          5          1         80
-/+ buffers/cache:          4        121
Swap:            3          0          3  

Is there any way to check memory usage per process in detail? For example something like this:

PID     USER           MEM    USD    SHRD     BUF    CAH  command
23      monitoring     23kb   12kb    10kb   23kb    5kb   du

If the above is not possible, then is there any way to check a specific amount of memory? (For example, I want to only check the cached memory and see how much each process has taken of it.)

1
  • 1
    You may take a look at /proc/[pid]/status in man 5 proc. The listed information varies across kernel versions, I wouldn't be sure about how useful it could be on your system.
    – fra-san
    Aug 31, 2020 at 17:05

1 Answer 1

1

I don't have Centos, but the man pages seem to correlate with Linux Mint, which I am using to investigate this. These features are IPCs (inter-process communication facilities).

Shared resources (almost by definition) do not belong to specific processes. So reporting everything would be double-counting in many cases.

I can see Shared memory segments listed using ipcs, and get more detail using:

ipcs | while read -r _ Id _; do
    [[ $Id =~ [0-9] ]] && ipcs -u -m -i $Id
done | more

These seem to maintain a cpid (creator pid) and a lpid (last accessor pid). Far as I can see, I have two kinds of shared memory.

(a) My control panel (mate-panel) has a share with each app it shows (mintUpdate, mate-sensors-ap, mate-screensave).

(b) My display server (Xorg) has a share with each window that can use the Edit menu (xed, terminal).

Device cache is also non-process -- it is related to any previously used file, even after the process which used that file has long ended. The space can be discarded immediately if required, but it is retained in the hope that some blocks from a recently-used file may be used again.

Virtual memory is frequently over-committed by reservations that are never actually used, so that too can be ephemeral.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .