> err 0xC0000005 # for hex 0xc0000005 / decimal -1073741819 STATUS_ACCESS_VIOLATION Check against Win32 error codes:
| Category | Range (Hex) | Example | Meaning | |----------|-------------|---------|---------| | | 0x00000000–0x0000FFFF | 1 , 2 | Custom error (e.g., invalid input) | | Win32 Error Codes | 0x00000000–0x0000FFFF (overlap!) | ERROR_FILE_NOT_FOUND (2) | System API failure | | NTSTATUS Codes | 0xC0000000–0xFFFFFFFF | 0xC0000005 | Access violation (structured exception) | | HRESULT | 0x80070000–0x8007FFFF | 0x80070002 | COM error, wraps Win32 error 2 |
This overlap is a trap: an exit code of 2 could mean "invalid parameter" (application-defined), or it could mean ERROR_FILE_NOT_FOUND from a failed CreateFile . Without the program's documentation, you cannot disambiguate. Three common scenarios produce exit codes that are technically correct but semantically useless: exit codes windows
Crucially, the exit code is the return value of main() in the C runtime sense. The CRT wraps main() , captures its return value, and passes it to ExitProcess() . If you never call ExitProcess explicitly, the CRT does it for you.
In the seemingly sterile output of a command-line program—a lone integer returned to the operating system—lies a sophisticated, often misunderstood contract between a process and its caller. On Windows, this integer is the exit code (or "return code"), and while the convention 0 for success and non-zero for failure is universal, the depth beneath is uniquely shaped by Windows' architecture, its legacy subsystems, and the perils of cross-platform assumptions. 1. The Kernel's Handshake: How Exit Codes Really Work When a Windows process terminates—whether by returning from main() , calling ExitProcess() , or suffering an unhandled exception—the kernel records a 32-bit unsigned integer inside the EPROCESS block. This value persists until the process object is reaped by WaitForSingleObject() or GetExitCodeProcess() . > err 0xC0000005 # for hex 0xc0000005 /
These are STILL_ACTIVE (thread) and STATUS_PENDING (process). Seeing them from GetExitCodeProcess means you called it before the process actually exited. This is a classic race.
This layering leads to a key insight: . The default for a thread is STATUS_THREAD_TERMINATED (0x00000100); for a process, it is STATUS_PENDING (0x00000103) until termination, then the final code. 2. The Semantic Wasteland: What Does Non-Zero Mean? Unlike Unix, where exit codes are small (0–255) and often mapped to sysexits.h conventions, Windows exit codes are full 32-bit values, blending several distinct categories: The CRT wraps main() , captures its return
> net helpmsg 2 The system cannot find the file specified. If the program is well-known (e.g., robocopy , xcopy ), consult its documentation—they reuse Win32 error codes with different meanings.
© Copyright 2017 Trần Bá Đạt Blog. Hosted by Vultr.