LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-18-2010, 05:43 AM   #1
rajesh1978
LQ Newbie
 
Registered: Jun 2010
Posts: 26

Rep: Reputation: 0
Post confusion about _exit


Hi,
I was reading difference between exit and _exit.

It tells that exit do the proper clean up but _exit does not.
exit flushes the buffer. So it is recomended that to use _exit in the child process.

My doubt is when we fork the memory space is also duplicated for child. Now child has it's own memory space. If I use exit in child then while exiting it will flush the buffer. It will not disturb the parent memory space(correct me if wrong).

So why there is a use of _exit.

and what sometime I see _exit(0) or some number inside the bracket. What does it mean

Last edited by rajesh1978; 06-18-2010 at 12:00 PM.
 
Old 06-19-2010, 12:21 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
"exit()" is the standard library call.

"exit()" is generally preferred.

The "status" parameter to both _exit() and exit() is the status value returned back to the operating system.

Here is the "man" page for "_exit()":
Code:
NAME
       _exit - terminate the current process

SYNOPSIS
       #include <unistd.h>

       void _exit(int status);

DESCRIPTION
       _exit terminates the calling process immediately. Any open
       file descriptors belonging to the process are closed;  any
       children  of the process are inherited by process 1, init,
       and the process's parent is sent a SIGCHLD signal.

       status is returned to the parent process as the  process's
       exit  status,  and  can be collected using one of the wait
       family of calls.

RETURN VALUE
       _exit never returns.

CONFORMING TO
       SVr4, SVID, POSIX, X/OPEN, BSD 4.3

NOTES
       _exit does not call any functions registered with the ANSI
       C atexit function and does not flush standard I/O buffers.
       To do these things, use exit(3).

SEE ALSO
       fork(2),   execve(2),   waitpid(2),   wait4(2),   kill(2),
       wait(2), exit(3)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the difference between exit() and _exit() vijaya_svk Programming 4 01-21-2008 06:11 PM
Error while compiling kernel 2.4.20-8 (conflicting return type of _exit function) samkraju Red Hat 1 07-01-2006 06:41 AM
difference between _exit and exit??? moonz Linux - Newbie 3 01-20-2006 11:05 AM
_exit() and exit() greghua Programming 3 10-08-2005 01:23 PM
a little confusion..... b0nd Linux - Newbie 1 02-17-2005 06:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration