• C

How can I know how much memory my process uses?

I'm runing a program that uses a lot of memory. How can I know how much memory does it use.
I would like to print the amount of memory it uses before aborting the porgram due to lack of memory.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What platform r u on
rchcAuthor Commented:
I run on Solaris 5.8 or linux
I think you should keep track of your dynamic memory allocation functions - malloc, calloc, free, realloc etc

Have a look at this site


Managing Security Policy in a Changing Environment

The enterprise network environment is evolving rapidly as companies extend their physical data centers to embrace cloud computing and software-defined networking. This new reality means that the challenge of managing the security policy is much more dynamic and complex.

A similar question was previously asked

here's a good discussion for the same


rchcAuthor Commented:
My code is a legacy one with thousands of lines. I can't keep track of each allocation.
I'm seeking a function that can tell me the amounr of memory allocated and or the free memory.
Is there such a function?
Use getrusage() to get the data size of the process or mallinfo() to get memory allocator statistics.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
As I said, the link on EE would be helpful
I am listing one of the solutions from there

Say u are using malloc for dynamic allocation

then just do this

#define malloc malloc_wrapper

malloc_wrapper ( same_arguments_as_malloc )
     /* do the accounting */
     malloc ( ... );
     return ...;
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.