Correct way to find memory used by process

Anirudh Sundar

New Member
Aug 14, 2018
Reaction score

I am running a C++ application on Redhat linux, built using gcc. The program works in a step by step manner, and each steps uses new and delete to allocate and remove memory for huge data structures. I've made sure that we are freeing all the memory allocated, but when I check for the memory used by process, it just keeps increasing.

I read that linux tries to reuse memory given to a process and hence sometimes doesn't reclaim the memory freed by the process. Is this true, and if so, how do I make sure that exactly how much memory my process is using currently, excluding the memory freed but kept by linux.

I'm checking for memory used by process right now in 2 ways. One using top/htop command and other is fetching the data from /proc/*/status file.

Could you let me know how to find the exact amount of memory (only the the amount of memory it holds right now, not the freed memory).


Hello @Anirudh Sundar and welcome to :)

I am a Home User and not familiar with the rest of your work, but the following command should apply to Red Hat as well


Mine, on Linux Mint 'Sylvia' 18.3 with 16GB RAM looks like this

chris@SylMATE-winTEST ~ $ free
total used free shared buff/cache available
Mem: 16320176 1154536 13882776 138756 1282864 14699664
Swap: 0 0 0

Is that the sort of info you are after?


Chris Turner

Edited added BTW

BTW - free -h will give the output in human readable form
Hi @wizardfromoz, thanks for the reply. If I'm not mistaken, free -h command gives the total amount of free and used memory in the entire system right? I wanted to know how to check the memory used by a specific process, like maybe the current process.

My question is basically similar to this thread in ubuntuforums that I found. I have the same issue as given there, my program seems to be releasing the memory, but when I check using the top/htop commands or check the /proc/*/status file, it shows that the process still occupies that memory.

That thread has answers where people say that linux sometimes doesn't immediately reclaim the memory allocated to some process for efficiency, so I wanted to know if there was any way to check the exact amount of memory used by my process.

Staff online

Members online