用C当前进程的内存使用情况 [英] Memory usage of current process in C

查看:306
本文介绍了用C当前进程的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在C当前进程的内存使用情况的人可以提供如何做到这一点Linux平台?

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?

我知道了执行cat / proc /&LT的;你的PID> /状态获得内存使用的方法,但我不知道如何捕获,在C

I'm aware of the cat /proc/<your pid>/status method of getting memory usage, but I have no idea how to capture that in C.

顺便说一句,它是一个PHP扩展我修改(当然,我是C新手)。如果有PHP扩展API中提供了快捷方式,这将是更有益的。

BTW, it's for a PHP extension I'm modifying (granted, I'm a C newbie). If there are shortcuts available within the PHP extension API, that would be even more helpful.

推荐答案

您永远可以在打开文件的/ proc 系统,你将一个普通文件(使用'自我'的符号链接,所以你不必看你自己的PID):

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.

这篇关于用C当前进程的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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