atexit(3) is a method for arranging a function to be called at a program's exit time.
Questions tagged [atexit]
162 questions
10
votes
1 answer
What is the difference between __cxa_atexit() and atexit()
In the GCC docs I found the -fuse-cxa-atexit option and it says the following:
This option is required for fully standards-compliant handling of static destructors
So what is the difference between the two? In the docs for __cxa_atexit I found the…

onqtam
- 4,356
- 2
- 28
- 50
9
votes
2 answers
How can I register a function to be called only on *successful* exit of my Python program?
I want to run a task when my Python program finishes, but only if it finishes successfully. As far as I know, using the atexit module means that my registered function will always be run at program termination, regardless of success. Is there a…

Ryan C. Thompson
- 40,856
- 28
- 97
- 159
8
votes
3 answers
How to use exit() safely from any thread
According to the man page (2) the exit function is not thread safe : MT-Unsafe race:exit, this is because this function tries to clean up resources (flush data to the disk, close file descriptors, etc...) by calling callbacks registered using…

ShellCode
- 1,072
- 8
- 17
8
votes
2 answers
Exists a way to free memory in atexit or similar without using global variables?
I am developing a project in C, and I need to free the allocated memory and also close all the open files before it exits.
I decided to implement a clean function that will do all this stuff and call it with atexit because there are a lot of…

sir psycho sexy
- 780
- 7
- 19
7
votes
2 answers
Better replacement for exit(), atexit() in C
I am new to C programming. I used to think using exit() was the cleanest way of process termination (as it is capable of removing temporary files, closing open files, normal process termination...), but when I tried man exit command on the terminal…

Adhamzhon Shukurov
- 681
- 1
- 8
- 21
7
votes
1 answer
std::atexit ordering when called from a global object's constructor
cppreference says about std::atexit :
The functions may be called concurrently with the destruction of the objects with static storage duration and with each other, maintaining the guarantee that if registration of A was sequenced-before the…

François Andrieux
- 28,148
- 6
- 56
- 87
7
votes
1 answer
Is it possible to change the exit code in a function registered with atexit()?
The man page for atexit(3) says the following:
POSIX.1-2001 says that the result of calling exit(3) more than once (i.e., calling exit(3) within a function registered using atexit()) is undefined. On some systems (but not Linux), this can result in…

Alexis King
- 43,109
- 15
- 131
- 205
7
votes
1 answer
.NET code execution at normal process exit?
In C there is the atexit function, which
The atexit() function registers the given function to be called at normal process termination, either via exit(3) or via return from the program's main().
Python has a similar capability.
Does .NET provide…

Wayne Werner
- 49,299
- 29
- 200
- 290
6
votes
3 answers
WSACleanup and atExit
Is it okay to register WSACleanup through atExit function ? We have several applications that can terminate at different points in the code so we would like to avoid putting WSACleanup everywhere throughought the code. Curently we call WSAStartup /…
user119666
6
votes
1 answer
Mixed-mode C++/CLI crashing: heap corruption in atexit (static destructor registration)
I am working on deploying a program and the codebase is a mixture of C++/CLI and C#. The C++/CLI comes in all flavors: native, mixed (/clr), and safe (/clr:safe). In my development environment I create a DLL of all the C++/CLI code and reference…

coderforlife
- 1,378
- 18
- 31
6
votes
2 answers
Break in Visual Studio on process exit
I'm having some difficulties determining what is causing a process to exit. I have a breakpoint in some shutdown code that I'm debugging, but, after breaking in the debugger at the breakpoint and stepping once, the whole process exits immediately.…

MuertoExcobito
- 9,741
- 2
- 37
- 78
6
votes
5 answers
python: closures and classes
I need to register an atexit function for use with a class (see Foo below for an example) that, unfortunately, I have no direct way of cleaning up via a method call: other code, that I don't have control over, calls Foo.start() and Foo.end() but…

Jason S
- 184,598
- 164
- 608
- 970
6
votes
5 answers
Is this the definitive ref counted Objective C singleton implementation?
Here is what I have concocted, after poring over the singleton literature.
Have I forgotten anything?
@implementation MySingleton
static MySingleton *mySharedInstance = nil;
//called by atexit on exit, to ensure all resources are freed properly…

Jacko
- 12,665
- 18
- 75
- 126
6
votes
1 answer
Flask and Web.py both hang on atexit
I have this simple Flask app:
from flask import Flask
import prolog_handler as p
app = Flask(__name__)
app.debug = False
@app.route('/')
def hello():
for rule in p.rules:
print rule
return 'hello'
if __name__ == '__main__':
…

John Thompson
- 1,674
- 1
- 20
- 35
5
votes
0 answers
Error with multiprocessing, atexit and global data
Sorry in advance, this is going to be long ...
Possibly related:
Python Multiprocessing atexit Error "Error in atexit._run_exitfuncs"
Definitely related:
python parallel map (multiprocessing.Pool.map) with global data
Keyboard Interrupts with…

mgilson
- 300,191
- 65
- 633
- 696