5

while using the size command in Unix systems with the executable or object files, we get output in the form of the size of text segment and data segment. Why doesn't it show the output for heap or stack segment? Below is the output of size command

 $ size hello_world-1 hello_world-1.o 


text   data   bss    dec   hex   filename
 916    256     4   1176   498   hello_world-1
  48      0     0     48    30   hello_world-1.o
trincot
  • 317,000
  • 35
  • 244
  • 286
Kamal Pandey
  • 182
  • 1
  • 1
  • 14

3 Answers3

6

Heap and stack are applicable to processes, which are (often) executables files loaded by the OS into memory, not to files stored on the file system directly.

Also, stack and heap size can vary during the lifetime of the process, so one could not, in general, predict how much stack or heap a certain executable file will take when loaded as a process.

This is why a command like size is not designed to show such information in addition to the size of code / data in the file itself.

Pac0
  • 21,465
  • 8
  • 65
  • 74
1

Because Heap section is used for dynamic memory allocation while the program is running, and the memory will be allocated during run time only because it is dynamic right. And for stack the variables stored there have local scope or block scope only and they also have there existence until the program runs.

And yes this stack,heap,data and code memory sections are in context of the process or the program which is running.

Stubborn
  • 780
  • 1
  • 5
  • 20
  • there is one more doubt? There is no global variable in hello_world-1.c file so the object file shows zero sizes for data and bss segment, but why does it show some size for the same executable. Please refer to my question for more clarification. – Kamal Pandey Apr 11 '18 at 07:25
  • @kamalpandey: you are forgetting the C runtime library – cdarke Apr 11 '18 at 07:50
0

They are OS processes they are not applicable to find size !

Bharadwaj
  • 135
  • 1
  • 1
  • 7