Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbosgd!gatech!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.ARPA (Doug Gwyn ) Newsgroups: net.lang.c,net.unix Subject: Re: return() vs. exit() vs. _exit() Message-ID: <1992@brl-tgr.ARPA> Date: Sat, 25-Jan-86 22:56:59 EST Article-I.D.: brl-tgr.1992 Posted: Sat Jan 25 22:56:59 1986 Date-Received: Wed, 29-Jan-86 04:14:28 EST References: <178@rexago1.UUCP> Distribution: net Organization: Ballistic Research Lab Lines: 28 Xref: watmath net.lang.c:7676 net.unix:6953 > I'm on a binary only 3b2/300 running SV.2.2 so... > > What's the difference between leaving main by return() vs exit() vs _exit()? > I mean in reality, by proposed standards (X3J11 can you hear me?), and > functionally (like on my machine). Who closes file descriptors? Who reclaims > memory? What about shared memory? What is a gate 4, 8? There is no difference between reality and the proposed standards. If main() is left via a return statement, the effect is exactly the same as termination via invocation of exit() with the return value used as the parameter to exit(). exit() is required to flush STDIO output buffers and do any other required cleanup. _exit() directly terminates the process without performing any extra actions along the way. _exit() is not available in all C implementations, although it is required on UNIX systems. "File descriptor" is a UNIX-only concept. Open file descriptors are closed by the UNIX kernel when a process terminates. The kernel is also responsible for memory allocation and sharing. GATE is similar to a subroutine jump except it switches into the kernel (acquires new PC & PSW), vectored through tables indexed by R0 and R1. This constitutes a "service call" or "system call". _exit() is normally implemented as a small piece of assembly- language code that simply invokes the appropriate system call, perhaps "gate 4,8". exit() normally calls _cleanup(), perhaps runs registered onexit handlers, then invokes _exit().