当前位置: 技术问答>linux和unix
如何得到程序本身占用的内存大小?
来源: 互联网 发布时间:2015-12-24
本文导语: 在linux下用c语言编写如何得到程序本身占用的内存大小?谢谢 最好有代码和要包含的头文件。 | Do you want to get the memory usage at runtime? 1) ps command from command line 2) process accounting by the kernel, bu...
在linux下用c语言编写如何得到程序本身占用的内存大小?谢谢
最好有代码和要包含的头文件。
最好有代码和要包含的头文件。
|
Do you want to get the memory usage at runtime?
1) ps command from command line
2) process accounting by the kernel, but you need the superuser right to enable the accounting. Refer to 8.14 of "advanced programming in the unix environment"
3) with the help of gdb
4) acctually you can calculate the static memory your program need.
1) ps command from command line
2) process accounting by the kernel, but you need the superuser right to enable the accounting. Refer to 8.14 of "advanced programming in the unix environment"
3) with the help of gdb
4) acctually you can calculate the static memory your program need.
|
/proc/atoi(getpid())/stat, mem, status等,里面有关于进程的状态,资源使用,文件名等所有信息。
|
ps -aux|grep [pid name]|grep -v grep |awk {print $4}
每4项就 是进程使用内存值
具体可看我blog:
如何获取系统信息
每4项就 是进程使用内存值
具体可看我blog:
如何获取系统信息