Results 1 to 4 of 4
Hi all,
I have a some confusion.please clarify my doubt.
I have a project in which many processes run. p1,p2,p3.
->There are some .so files are included in some process ...
- 07-12-2010 #1Just Joined!
- Join Date
- Jun 2010
- Posts
- 8
difference between init and main function in a process
Hi all,
I have a some confusion.please clarify my doubt.
I have a project in which many processes run. p1,p2,p3.
->There are some .so files are included in some process when needed
example ppp.so in process p1 (when ppp is needed and will go like a plugin)
but it has a init () function
how a process includes a init() function ?
->process p1 has main function i.e main()
->so evry process has main() right ?
what is the difference between init () and main () functoins.
where is init () used and how many init() a process van have ?
Please clarify my doubt .
Thanks in advance
- 07-14-2010 #2Just Joined!
- Join Date
- Jul 2010
- Posts
- 53
the loader can be told to use an alternative init function - but you shouldn't need to do that.
normally the loader will look for _start, this will call main()
dynamic libraries can have an init function to call when they are opened, see man page for dlopen()
if you have a function called init() - the C compiler generates this entry point as _init - which the dynamic library loader will call first. also a function called fini() will be called on dlclose().
unless you are certain to want this then you will want to not have functions called init() and fini() in your dynamic library.
readelf utility, sometimes objdump, will let you look at the .so and the binary executable (which can have 1 and only 1 main() function).
- 07-14-2010 #3Just Joined!
- Join Date
- Jun 2010
- Posts
- 8
Thanks for wonderful response .
But one more clarification .what is the difference
between _init and init (why _ is used before init)
looking for start means it can start with any one fun i.e either _init or _start
Thank you very much in advance
- 07-14-2010 #4Just Joined!
- Join Date
- Jul 2010
- Posts
- 53
the leading '_' is the usual standard for symbols generated by the C compiler
is possible to inhibit the default behavior, but generally any function foo() will generate the symbol _foo for entry point in the object produced by the compiler.
symbol names _start, _init, _fini, and others are accepted convention but can be modified at link time (using linker options, even modified linker scripts) and queried in the elf (or other) headers.


Reply With Quote