I\'ve been trying to figure out how the fork-exec mechanism is used inside Linux. Everything was going on according to the plan until some web pages started to confuse me.<
exit()
flushes io buffers and does some other things like run functions registered by atexit()
. exit()
invokes _end( )
_exit()
just ends the process without doing that. You call _exit()
from the parent process when creating a daemon for example.
Ever notice that main()
is a function? Ever wonder what called it in the first place?
When a c program runs the shell you are running in provides the executable path to 'exec' system call and the control is passed to kernel which in turn calls the startup function of every executable _start()
, calls your main()
, when main()
returns it then calls _end()
Some implementations of C use slightly different names for _end()
& _start()
...
exit()
and _exit()
invoke _end()
Normally - for every main()
there should be one & only one exit()
call. (or return at the end of main()
)