difference between exit() and _exit()

By using exit() and _exit() we can terminate a program. What is the:confused: difference between these two ???

read more about this on the unixguide programming page.

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 it starts of with something usually called '_start()', calls your main(), when main() returns it then calls '_end()' Some implementations of C use slightly sifferent 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() )

The functions exit and _exit are equivalent except that exit calls functions registered by atexit and flushes standard I/O buffers while _exit does not.

With _exit(), whether open streams are closed (without flushing) is implementation-defined.

There is also _Exit() which not many people are yet aware of. See _Exit