How can I reduce the memory footprint of a minimal Linux process

一笑奈何 提交于 2019-12-08 18:32:15

问题


Consider the following C program, 'pause.c':

void main() { pause(); }

Compiling this on x64 Linux 3.0.0-16-generic using this command 'gcc -Os pause.c -o pause' produces an executable of size ~8KB. When I run this executable and examine its precise memory footprint using 'pmap -d PID', it shows me that the private memory allocated to the process is 192KB (it varies across different systems usually, between 128KB and 192KB).

Examining the process using valgrind and massif fails to detect any memory allocation events. I was sceptical that the 192KB figure was accurate but I found that starting 5 instances of the 'pause' process did consume approximately 1MB of system memory.

I'm at a loss to explain the origin of this memory, can anyone provide some insight on why this memory is being allocated and any potential actions which could reduce it?, cheers.


回答1:


Reducing the stack limit will lower the memory footprint:

ulimit -s 8


来源:https://stackoverflow.com/questions/9887676/how-can-i-reduce-the-memory-footprint-of-a-minimal-linux-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!