Memory usage of current process in C

后端 未结 7 1516
深忆病人
深忆病人 2020-12-01 04:22

I need to get the memory usage of the current process in C. Can someone offer a code sample of how to do this on a Linux platform?

I\'m aware of the cat /proc/

7条回答
  •  鱼传尺愫
    2020-12-01 05:08

    You can always just open the 'files' in the /proc system as you would a regular file (using the 'self' symlink so you don't have to look up your own pid):

    FILE* status = fopen( "/proc/self/status", "r" );
    

    Of course, you now have to parse the file to pick out the information you need.

提交回复
热议问题