Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's actually quite hard to do exit cleanups, even by putting functions into `.__fini_array`. The reason is because some signals (SIGTERM, SIGKILL) cannot be masked, when a thread/process (`task_struct`) got `SIGKILL`-ed, there's no way for application to run functions (including .__fini_array). Things can get more complicated when a thread calls `exit_group`, which is also recommended, cause all other threads in the same process group receive `SIGKILL`, hence none of the other threads are able to run any code after.


There's also the matter of someone forcibly pulling a machine's power cord. In some sense exit cleanups are fundamentally unreliable.


A significant amount of code can be run after a power cord pull is detected but before the big caps discharge on most boxes. But yea no userspace program is going to get those cycles...


> The reason is because some signals (SIGTERM, SIGKILL) cannot be masked

SIGTERM can be masked. SIGKILL and SIGSTOP are the only ones that can't be.


Thanks for the correction




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: