Quoting the man page for _exit()
The _Exit()
and _exit()
functions shall not call functions registered with atexit()
nor any registered signal handlers. Whether open streams are flushed or closed, or temporary files are removed is implementation-defined. Finally, the calling process is terminated with the consequences described below.
So what you're seeing is expected behavior.
That said, you should include unistd.h
(for _exit()
)and stdlib.h
(for atexit()
) headers for including the prototype.
If you want the functions registered by atexit()
to be invoked, you should call exit()
instead.
The exit()
function shall first call all functions registered by atexit()
, in the reverse order of their registration, [....]