return() vs. exit() vs. _exit()
Joseph S. D. Yao
jsdy at hadron.UUCP
Mon Jan 27 05:07:01 AEST 1986
In article <178 at rexago1.UUCP> rich at rexago1.UUCP (K. Richard Magill) writes:
>What's the difference between leaving main by return() vs exit() vs _exit()?
Functionally, return and exit should be identical. Your 'lint'
(s5r2.0v2) prob'ly complains if you use exit() tho. The code goes
roughly like:
[C header, crt0.s:]
push envp
push argv
push argc
call $3, _main
push r0
call $1, $_exit
sys $exit_system_call
halt
Note that exit(main(argc, argv, envp)) is the effect.
The exit() code resembles:
exit(val)
int val;
{
register FILE *fp;
for (fp = _iob; fp < &_iob[NIOBUFS]; fp++)
if fp has been opened
fclose(fp);
_exit(val);
}
..........
__exit:
move arg to r0
sys $exit_system_call
Shared and local memory are reclaimed by the kernel after an exit()
system call.
> ... What is a gate 4, 8?
Got my curiosity piqued.
--
Joe Yao hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}
More information about the Comp.lang.c
mailing list