Re: exit and _exit calls

From: Floyd L. Davidson (floyd_at_apaflo.com)
Date: 07/11/05


Date: Mon, 11 Jul 2005 07:16:31 -0800


"Rajan" <rstalekar@yahoo.com> wrote:
>Whatever you thought is not what the UNIX faq says, see the link below
>http://www.erlenstar.demon.co.uk/unix/faq_2.html
>
>It says :-
>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.

Whatever you thought, the FAQ gives you additional background
information, answering specific questions, but does *not* define
the C language. You are reading far more into the FAQ than it
says. But worse you are ignoring documentation that does intend
to be the complete definition.

Read the man pages for exit(3) and _exit(2), and first take note
that (as befits what the FAQ says) exit() is in Section 3 and
_exit() is part of Section 2.

There are two other items to note. One is that the man pages
provide significantly more information, in distinctly pedantic
terminology, than does the FAQ. That is of course the
distintion between a man page and a FAQ. Second is that both
functions conform to the ANSI/ISO C Standard; and hence that
document should also be consulted if you want the definitive
statement on what those two functions must do. (See Sections
7.20.4.3 and 7.20.4.4.)

Specifically, one statement in the C Standard needs to be
emphasized, if you want to understand the statements in the FAQ:

   2 The exit function causes normal program termination to
     occur. If more than one call to the exit function is
     executed by a program, the behavior is undefined.
         7.20.4.3 ISO/IEC 9899:1999 (E)

That is why _exit(2) is necessary. If a program forks and
both resulting processes call exit(3), the result is undefined
behavior.

-- 
Floyd L. Davidson           <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)                         floyd@barrow.com


Relevant Pages

  • Re: Sequence matching exercise
    ... The program should exit ... Then write a program to support the parse ... your next homework assignments. ... C++ Faq: http://www.parashift.com/c++-faq-lite ...
    (comp.lang.c)
  • Re: problem with sizeof in while loop reading a file
    ... You could use "return 0" here in place of exit. ... The start-up code that gets executed right before mainmight have the ... Bart v Ingen Schenau ... a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq ...
    (comp.lang.c)
  • Re: EXIT_SUCCESS in C++
    ... Anand Hariharan wrote: ... > OP didn't mention anything about exit(). ... exitdoes clean up all ... a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq ...
    (alt.comp.lang.learn.c-cpp)
  • Verifying valid input in a loop
    ... I have read part seven of the FAQ and searched for an answer but can ... valid input is entered. ... loop to allow for another chance at input not exit the loop. ...
    (comp.lang.cpp)