在Linux / Windows的C / C ++内存使用API [英] C/C++ memory usage API in Linux/Windows

查看:558
本文介绍了在Linux / Windows的C / C ++内存使用API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得每两个全流程和系统内存使用信息。在Windows中,它是pretty容易。 GetProcessMemoryInfo和GlobalMemoryStatusEx很大,很容易做这些工作。例如,GetProcessMemoryInfo给出给定的过程的PeakWorkingSetSize。 GlobalMemoryStatusEx返回系统范围内的可用内存。

I'd like to obtain memory usage information for both per process and system wide. In Windows, it's pretty easy. GetProcessMemoryInfo and GlobalMemoryStatusEx do these jobs greatly and very easily. For example, GetProcessMemoryInfo gives "PeakWorkingSetSize" of the given process. GlobalMemoryStatusEx returns system wide available memory.

不过,我需要做的是在Linux上。我试图找到Linux系统的API,是等价GetProcessMemoryInfo和GlobalMemoryStatusEx。

However, I need to do it on Linux. I'm trying to find Linux system APIs that are equivalent GetProcessMemoryInfo and GlobalMemoryStatusEx.

我发现'的getrusage。然而,最大ru_maxrss(驻留集大小)的结构 rusage 仅仅是零,这是不执行。另外,我也没办法让整个系统的可用内存。

I found 'getrusage'. However, max 'ru_maxrss' (resident set size) in struct rusage is just zero, which is not implemented. Also, I have no idea to get system-wide free memory.

它当前的解决办法,我使用系统(PS -p%my_pid -o VSZ,RSZ);。手动记录到文件中。但是,它的脏和不方便处理数据。

Current workaround for it, I'm using "system("ps -p %my_pid -o vsz,rsz");". Manually logging to the file. But, it's dirty and not convenient to process the data.

我想知道一些花哨的Linux应用程序接口用于这一目的。

I'd like to know some fancy Linux APIs for this purpose.

推荐答案

您可以看到它是如何在 libstatgrab

而且你还可以用它(GPL)

You can see how it is done in libstatgrab.
And you can also use it (GPL)

这篇关于在Linux / Windows的C / C ++内存使用API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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