[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: RFE: refman - adding mention of os.exit not closing variables with default arguments.
- From: Sean Conner <sean@...>
- Date: Wed, 24 Jun 2020 17:00:09 -0400
It was thus said that the Great Lorenzo Donati once stated:
>
> However I thought C's `exit` was the right way to exit a program
> (possibly together with `atexit` mechanism) if returning from main is
> too cumbersome.
In C89, you have exit(). In C99, you have exit() and _Exit(). In C11,
you have exit(), _Exit() and quick_exit(). Here's what each does.
exit()
Run each function registered by atexit() in reverser order
of registration (at least 32 such functions are supported).
Write buffered data in open files, and close all open files.
All files created with tmpfile() are removed.
Return the status code to the operating system.
_Exit()
Return the status code to the operating sytem.
quick_exit()
Run each function registered by at_quick_exit() in reverse
order of registration (at least 32 such functions are
supported).
Return the status code to the operating system.
_Exit() does the least amount of work, exit() the most. The only
resources that are cleaned up by the C standard library are files (and only
in the case of exit()); memory is not mentioned at all, and in my
experience, on non-virtual memory systems (like MS-DOS or AmigaOS 1.x) this
means it is leaked.
Also, calling exit() is the same a doing a return from main---that is,
when you return from main, the process is as if you called exit().
Why one would call quick_exit() or _Exit() is highly dependent upon the
operating system and nature of the program.
-spc