如何获取进程的总堆大小 [英] How to get total heap size of a process

查看:176
本文介绍了如何获取进程的总堆大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有什么方法可以在Linux平台上获得分配给进程的总堆大小




问候,

Ganesh

解决方案

ga ************* @ gmail.com 写道:


有没有什么办法可以在Linux平台上的c中分配给一个进程的总堆大小。



在Linux组中提问?堆大小是操作系统问题,而不是C问题。


-

Ian Collins。


< BLOCKQUOTE>" GA ************* @ gmail.com"写道:


有没有什么办法可以在Linux平台上的c中获得分配给进程的总堆大小。




不可移植,这是唯一重要的方式。


-

我们的敌人是创新和足智多谋的,我们也是。

他们从不停止思考伤害我们国家的新方法

和我们的员工,我们也不会。 - G. W. Bush。

人们总是可以接受

领导人的竞标。所有你需要做的就是告诉他们他们正在遭受攻击并谴责和平主义者因缺乏爱国主义而使国家陷入危险之中。它的工作方式与任何国家/地区的b $ b相同。 --Hermann Goering。


ga ** ***********@gmail.com écrit:


有没有办法让分配给进程的总堆大小
在linux平台上的c。

问候,
Ganesh




这可以给你一个近似值:


#include< stdio.h>

#include< stdlib.h>


int main(void )

{

unsigned int size = 1;

unsigned int * p =& size;


while(p){

p = malloc(size);

if(p){

free(p);

size * = 2;

}

}

printf(" Stopped at size =%u \ n" ;,尺寸);

}


Hi,
Is there any way to get the total heap size allocated to a process
in c on linux platform.

Regards,
Ganesh

解决方案

ga*************@gmail.com wrote:

Hi,
Is there any way to get the total heap size allocated to a process
in c on linux platform.


Ask in a Linux group? Heap size is an OS issue, not a C one.

--
Ian Collins.


"ga*************@gmail.com" wrote:


Is there any way to get the total heap size allocated to a process
in c on linux platform.



Not portably, which is the only way that counts.

--
"Our enemies are innovative and resourceful, and so are we.
They never stop thinking about new ways to harm our country
and our people, and neither do we." -- G. W. Bush.
"The people can always be brought to the bidding of the
leaders. All you have to do is tell them they are being
attacked and denounce the pacifists for lack of patriotism
and exposing the country to danger. It works the same way
in any country." --Hermann Goering.


ga*************@gmail.com a écrit :

Hi,
Is there any way to get the total heap size allocated to a process
in c on linux platform.

Regards,
Ganesh



This could give you an approximation:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
unsigned int size=1;
unsigned int *p = &size;

while (p) {
p = malloc(size);
if (p) {
free(p);
size *= 2;
}
}
printf("Stopped at size=%u\n",size);
}


这篇关于如何获取进程的总堆大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆