The unix way is that if you are a child of fork , then you call _exit . The main difference between exit and _exit is that exit displays more - calls atexit , flushes stdio , etc. handlers, while _exit does the minimal amount of material in user space, just forcing the kernel to close all its files, etc. d.
This is very well ported to the python world with sys.exit , doing what exit does, and doing more than os._exit python interpreter, where os._exit makes it as minimal as possible.
If you are a child of fork and you call exit rather than _exit , then you can end up calling call handlers, which the parent will call again when it exits due to undefined behavior.
source share