简体   繁体   English

如何使用C / C ++系统调用获取Linux中进程的堆内存的当前大小?

[英]How do I get the current size of the heap memory of a process in Linux using C/C++ system calls?

I am working on a software library, which can constantly keep track of the size of the heap memory of programs written in C/C++. 我正在开发一个软件库,该库可以不断跟踪用C / C ++编写的程序的堆内存大小。

What I would like to do is as follows. 我想做的如下。

void check_memory(){

  heap_size = get_process_heap_size(.....);

  if(heap_size>=upper_bound){

    //do something to reduce the heap size

    heap_size = get_process_heap_size(.....); 
  }
}

Is there any system call in C/C++ that is equivalent to get_process_heap_size() in the code above? C / C ++中是否有任何与上面代码中的get_process_heap_size()等效的系统调用?

我不知道是否有任何直接的系统调用可以为您提供内存详细信息,但是如果您使用的是Linux,则可以读取和解析/ proc /(进程的pid)/状态文件来获取所需的内存使用计数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM