1

Actually my code has malloc. I'm using ubuntu OS and I want to know how much heap memory is used?

Is there any command by which I can find how much heap a running process has used in ubuntu OS?

Say now the malloc is in infinite loop and it is running in one terminal and using another terminal I would like to know how much Heap memory is occupied by that running process

trincot
  • 317,000
  • 35
  • 244
  • 286
Mohammed
  • 15
  • 3

2 Answers2

0

you can use /proc file system

/proc/pid/shmam

It will tell you exactly how much memory it is using at that time.

for detailed inputs refer

https://serverfault.com/questions/48582/how-is-memory-usage-reported-in-linux
How to measure actual memory usage of an application or process?

Community
  • 1
  • 1
Pradheep
  • 3,553
  • 1
  • 27
  • 35
0

If you really want to know what amount of memory your application actually uses, you need to run it within a profiler. For example, valgrind can give you insights about the amount of memory used, and, more importantly, about possible memory leaks in your program.

look into, http://valgrind.org/docs/manual/mc-manual.html

Valgrind is basically an x86 emulator that checks all reads and writes of memory, intercepts all calls to allocate and deallocate memory. The memcheck tool of valgrind can detect the following:

1) Use of uninitialised memory,

2) Reading/writing memory after it has been free'd

3) Reading/writing off the end of malloc'd blocks

4) Reading/writing inappropriate areas below the stack.

5) Memory leaks

6) Mismatched use of malloc/new/new[] vs free/delete/delete[]

7) Overlapping src and dst pointers in memcpy() and related functions

8) Doubly freed memory

9) Passing unaddressable bytes to a system call

Kinjal Patel
  • 405
  • 2
  • 7