What is the difference between exit(), _exit() and _Exit() in C?
How do I decide which to use?
On bash, <
Normative in C99 are exit
and _Exit
.
The difference between the two is that exit
also executes the handlers that may be registered with atexit
and closes streams etc whereas _Exit
doesn't call the atexit
routines and may or may not close streams properly.
_exit
is from POSIX and has similar properties as _Exit
with the difference that it is guaranteed to close streams properly.
In summary, whenever you can you should use exit
, this is the cleanest way to terminate.