Skip to main content

Module process_exit

Module process_exit 

Source
Expand description

Emergency process termination that skips libc exit cleanup on Unix.

std::process::exit delegates to libc’s exit, which runs atexit handlers and thread-local destructors and tears down process-wide state Rust shares with libc and the kernel — notably the main thread’s alternate signal stack. Calling it from a child thread races the still-running main thread: a destructor can be dropped twice, or the alt stack the main thread still relies on can be unmapped. VT Code’s emergency exits run on a Tokio task (double Ctrl+C) and on the signal_hook thread (SIGTERM), so both are exposed to that class of bug.

These paths have already restored the terminal and flushed their own output before exiting, so they do not need libc’s cleanup. On Unix we use the raw _exit syscall to skip it entirely; other platforms keep std::process::exit.

Functions§

emergency_exit
Terminate the process immediately with code.