Reputation: 4412
In answer to this question, some people have said to use _Exit() and others have said to use _exit(). Could someone explain the difference (if any) between the two, and the origins of both?
Upvotes: 6
Views: 3448
Reputation: 1441
_exit()
and _Exit()
are absolutely identical. To understand the differences between exit()
and _exit()
, you would need to know about the functions on_exit(3)
and atexit(3)
. These functions are used to register functions that are called automatically when the process exits normally, that is, via a return from main()
, or via a call to exit()
. on_exit()
and atexit()
differ only in that they allow functions to be registered with different signatures (think of these registered functions as destructors (as in object-oriented programming) for the processes).
exit()
, upon being called attempts to execute all the functions registered using atexit()
or onexit()
. Upon executing them, it calls _exit()
. _exit()
does the normal process termination stuff - closing file-descriptors, releasing memory, re-parenting orphaned children to init, et cetera. Think of _exit()
as the bare-bones system call used by a process to terminate itself.
Since a whole lot of applications do not use atexit()
or on_exit()
, for these, _exit()
, _Exit()
, and exit()
behave identically.
Upvotes: 1
Reputation: 12205
Right from the man page here:
The function _Exit() is equivalent to _exit().
Although in C++11, it is standardized as either std::_Exit or std::quick_exit. According to Mike Seymour here.
Upvotes: 7
Reputation: 10717
_Exit(2)
is from C99. _exit(2)
is from POSIX. At least, according to the manpage I have installed here.
They are entirely equivalent.
Upvotes: 5