Understanding Very Minimal C Program and its execution in Ubuntu Linux – Part 1

Following is the very minimum syntax required for the “C” program, we can call it as the first C program which we can write.

 $ vim minimum-c-program.c 
main() {

That is, the most minimum syntax required for a simple C program should contain 3 important things as,
1. main function which is the entry point of the C program
2. open & close bracket () after main
3. open & close curly brace {}

Now, Lets try to compile this program as,

$ gcc -o minimum-c-program_exe minimum-c-program.c 

Execute the binary executable created using above command as,


Now, we can check code & data size of this program as,

$ size minimum-c-program_exe
   text	   data	    bss	    dec	    hex	filename
   1017	    272	      4	   1293	    50d	minimum-c-program
$ nm -S minimum-c-program
0804a018 B __bss_start
0804a018 00000001 b completed.7200
0804a010 D __data_start
0804a010 W data_start
08048320 t deregister_tm_clones
08048390 t __do_global_dtors_aux
08049f0c t __do_global_dtors_aux_fini_array_entry
0804a014 D __dso_handle
08049f14 d _DYNAMIC
0804a018 D _edata
0804a01c B _end
08048454 T _fini
08048468 00000004 R _fp_hw
080483b0 t frame_dummy
08049f08 t __frame_dummy_init_array_entry
08048558 r __FRAME_END__
         w __gmon_start__
08048470 r __GNU_EH_FRAME_HDR
0804828c T _init
08049f0c t __init_array_end
08049f08 t __init_array_start
0804846c 00000004 R _IO_stdin_used
         w _ITM_deregisterTMCloneTable
         w _ITM_registerTMCloneTable
08049f10 d __JCR_END__
08049f10 d __JCR_LIST__
         w _Jv_RegisterClasses
08048450 00000002 T __libc_csu_fini
080483f0 0000005d T __libc_csu_init
         U __libc_start_main@@GLIBC_2.0
080483db 0000000a T main
08048350 t register_tm_clones
080482e0 T _start
0804a018 D __TMC_END__
08048310 00000004 T __x86.get_pc_thunk.bx

You can check which libraries this program uses using following command,

$ ldd minimum-c-program_exe
	linux-gate.so.1 =>  (0xb7722000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb753d000)
	/lib/ld-linux.so.2 (0x80038000)

The other important commands you can try to udnerstand are as bellow,

 $ objdump -Dxls minimum-c-program_exe 
 $ readelf -a minimum-c-program_exe 

In the next post, we will try to understand how this program executes in run time as “Understanding execution of very minimal C program in Linux / Ubuntu


Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )


2 thoughts on “Understanding Very Minimal C Program and its execution in Ubuntu Linux – Part 1”

Leave a Comment

Android Android Applications Android Build system Android Commands Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development & Build Development, Debugging and Performance Tools Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web design and development Website Hosting Wordpress Yocto / Bitbake / Openembedded