difference between exit() and _exit()


 
Thread Tools Search this Thread
Top Forums Programming difference between exit() and _exit()
# 1  
Old 08-12-2009
difference between exit() and _exit()

By using exit() and _exit() we can terminate a program. What is theSmilie difference between these two ???
# 2  
Old 08-12-2009
Quote:
"The basic difference between exit() and _exit() is that the former performs clean-up related to user-mode constructs in the library, and calls user-supplied cleanup functions, whereas the latter performs only the kernel cleanup for the process."
read more about this on the unixguide programming page.
# 3  
Old 08-12-2009
exit() flushes io buffers and does some other things like run functions registered by atexit(). exit() invokes _end( )

_exit() just ends the process without doing that. You call _exit() from the parent process when creating a daemon for example.



Ever notice that main() is a function? Ever wonder what called it in the first place?
When a c program runs it starts of with something usually called '_start()', calls your main(), when main() returns it then calls '_end()' Some implementations of C use slightly sifferent names for _end() & _start()...

exit() and _exit() invoke _end()


Normally - for every main() there should be one & only one exit() call. (or return at the end of main() )
# 4  
Old 08-12-2009
The functions exit and _exit are equivalent except that exit calls functions registered by atexit and flushes standard I/O buffers while _exit does not.
# 5  
Old 08-13-2009
With _exit(), whether open streams are closed (without flushing) is implementation-defined.

There is also _Exit() which not many people are yet aware of. See _Exit
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to calculate difference of split and sum the difference

In the awk I am trying to subtract the difference $3-$2 of each matching $4 before the first _ (underscore) and print that value in $13. I think the awk will do that, but added comments. What I am not sure off is how to add a line or lines that will add sum each matching $13 value and put it in... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Difference between exit, bye and quit in sftp

Hi All, I would like to know whether is there any difference in closing the sftp connection with exit, bye and quit. And would like to know the reliable command. (3 Replies)
Discussion started by: Girish19
3 Replies

3. Shell Programming and Scripting

Need the difference between exit 1 & exit 7

Hi In one of the script I am seeing some thing like exit 7,exit 1,exit 2,exit 3,exit 9,exit6.What is the difference between all of this exit.Can anyone help here please (3 Replies)
Discussion started by: ginrkf
3 Replies

4. Programming

what is the main difference between difference between using nonatomic lseek and O_APPEND

I think both write at the end of the file ...... but is there a sharp difference between those 2 instruction ..... thank you this is my 3rd question today forgive me :D (1 Reply)
Discussion started by: fwrlfo
1 Replies

5. Shell Programming and Scripting

RE: exit value

I am running HP-UX & ksh I have several validation programs that scan log files for error messages. One of these files scan 3 diff files, thus I have the exit value in a variable and depending on which log-file I am scanning the value changes. I am not getting the value I expect but a... (1 Reply)
Discussion started by: vslewis
1 Replies

6. UNIX for Dummies Questions & Answers

"_exit(-1)" command gives core dump ..

Hi, I am getting fatal error or core dump by using this command "_exit(-1)". I need to terminate the program at a certain condition, but continous calling of this exit function, I am getting core dump. Is there any other command can be used to avoid the core dump ?? (3 Replies)
Discussion started by: ronix007
3 Replies

7. Shell Programming and Scripting

difference b/t the exit codes $* and $@

I know that the exit codes in scripting "$*" will returns all the parameters/arguments passwd to the script. But I also know that "$@" will also returns the same. What is the difference between those two ? (1 Reply)
Discussion started by: praveen_b744
1 Replies

8. UNIX for Dummies Questions & Answers

what is meaning of exit(0) and exit(1)

can u tell me what is the meaning of exit(0),exit(1),exit(2) what is diff amonng these. Amit (1 Reply)
Discussion started by: amitpansuria
1 Replies

9. Programming

exit(0) versus exit(1)

What is the difference between using exit(0) and exit(1) to exit a program? Which should I use? (9 Replies)
Discussion started by: enuenu
9 Replies

10. UNIX for Dummies Questions & Answers

Where can I find a list of exit codes? (Exit code 64)

I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)
Discussion started by: jkuchar747
3 Replies
Login or Register to Ask a Question