简体   繁体   中英

how to know the memory footprint of my binary executable

I wonder if there is a way to know the memory footprint of my binary executable coded in C language.

informations about binary executable : compiled with toolchain of OpenWrt branch (Attitude Adjustment) and its architecture is x86

On a Linux/Unix system, you can use the size command for this, eg on my Ubuntu system

size /bin/sh
   text    data     bss     dec     hex filename
 102134    1776   11272  115182   1c1ee /bin/sh

Since this is OpenWrt, if you have a different architecture, eg MIPS or ARM or something else, you must pick the size command of the appropriate toolchain, of course.

The sections have the following meaning

  • text denotes the code size of the executable
  • data is initialized data section, eg variables, like int v = 17; or char name[] = "Tom";
  • bss is the uninitialized or simply 0 initiailized section, int a; or double amount;
  • dec is the overall size, in this case 102134 + 1776 + 11272 = 115182
  • hex finally is also the overall size, as a hex value 1c1ee = 115182

But this does not include the stack or any dynamic heap memory. To see the overall memory usage at runtime, you must look at ps or top output.

要了解运行时的内存使用情况,在Linux系统上可以使用valgrindmemcheck工具。

top

and advanced one called

htop

are the tools to monitor any executable runing in linux system

Use the Command size <binary> to get the memory footprint of your binary executable. Check the size manual ( man size ) for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM