What is the difference between exit(), _exit() and _Exit() in C?
How do I decide which to use?
On bash,
man 2 exit
gave me the page _EXIT(2), whereas
man 3 exit
gave the page EXIT(3).
What is the difference between exit(), _exit() and _Exit() in C?
How do I decide which to use?
On bash,
man 2 exit
gave me the page _EXIT(2), whereas
man 3 exit
gave the page EXIT(3).
exit()
terminating after cleanup._exit()
terminating immediately after call.If you have some stack corrupted while
exit()
function was called program may close with Segmentation Fault, if you are use_exit()
, program exit in quick mode.From http://msdn.microsoft.com/en-us/library/6wdz5232.aspx you have
exit()
- Performs complete C library termination procedures, terminates the process, and exits with the supplied status code._exit()
- Performs quick C library termination procedures, terminates the process, and exits with the supplied status code._cexit()
- Performs complete C library termination procedures and returns to the caller, but does not terminate the process._c_exit()
- Performs quick C library termination procedures and returns to the caller, but does not terminate the process.1.exit() : it's cleanup the work like closing file descriptor, file stream and so on, 2._exit() : it's not cleanup the work like closing the file descriptor,file stream and so on
These are the major difference of exit() and _exit().
am i rectified ur answer
From man:
Normative in C99 are
exit
and_Exit
.The difference between the two is that
exit
also executes the handlers that may be registered withatexit
and closes streams etc whereas_Exit
doesn't call theatexit
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.