Reputation: 733
I have used exit()
to terminate the process. I do not have any exit handlers registered also I do not care about flushing buffers on exit, so thought of using _exit()
as more robust method to terminate process.
The only question is, does _exit()
handles closing of all open file descriptors and open sockets gracefully?
Upvotes: 2
Views: 1910
Reputation: 4364
Yes, it is. Actually, on most platforms, operating system closes files and sockets for terminated process, so it doesn't matter if it finished with _exit()
, exit()
, assert(false)
or kill -KILL
.
Note that stdio FILE *
streams are NOT closed correctly by _exit()
and any unwritten (still buffered) data will be lost.
Upvotes: 3
Reputation: 182664
The function exit
calls _exit
. From TLPI:
The following actions are performed by exit():
- Exit handlers are called
- The stdio stream buffers are flushed
- The _exit() system call is invoked
The standard page for _exit says this:
All of the file descriptors, directory streams, conversion descriptors, and message catalog descriptors open in the calling process shall be closed.
Upvotes: 6