What is the difference between exit() and _exit() system call?


Should I employ exit(int status) or _exit(int status) to exit() from a child process? Does this question haunt you quite often? If so, this post is for you.

The exit() method which is part of the C library routines calls the kernel system call _exit() internally.

The responsibility of the kernel system call _exit() includes asking the kernel to close any open descriptors, free the memory used by the process and perform terminating process clean-up. Whereas the exit() call takes care of flushing the I/O buffers and perform additional clean-up before invoking _exit() internally.

In simpler words, exit() performs clean-up related to user-mode constructs in the library, and calls user-supplied cleanup functions whereas _exit() performs only the kernel level cleanup for the process.

It’s always advisable to use _exit(int status) in a child because employing exit(int status) can lead to stdio buffers being flushed twice, and temporary files being unexpectedly removed.

Finally, exit(int status) is defined in stdio.h and _exit(int status) is defined in unistd.h file.

Disclaimer

All data and information provided on this site is for informational purposes only. sks8.wordpress.com or skumar.co.nr makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis. Any trademarks, if at all displayed on this blog belong to their respective owners.

Reblog this post [with Zemanta]
Advertisements

The URI to TrackBack this entry is: https://sks8.wordpress.com/2009/09/01/difference-between-exit-and-_exit/trackback/

RSS feed for comments on this post.

One CommentLeave a comment

  1. explanation is very clear i was satisfied about that answer of difference between exit and _exit


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: