titanandrews
Programmer
Hi All,
Is there any way to catch the exit code from someone calling exit(status) and check the value before the program terminates?
Just for an idea, the code I'm thinking of is something like this:
This is for Windows, but I am looking for a solution for UNIX/Linux. BTW... this solution does NOT work because the process has not yet terminated when my exit handler is called, thus resulting in exitCode of 259 instead of 55. 259 on Windows means the process is still active.
Does anyone know if this can be done?
Use case: Imagine you have a library and you want to check if someone is calling exit with a particular code.
Is there any way to catch the exit code from someone calling exit(status) and check the value before the program terminates?
Just for an idea, the code I'm thinking of is something like this:
Code:
void exithandler()
{
DWORD exitCode = 0;
::GetExitCodeProcess(GetCurrentProcess(),&exitCode);
std::cout << exitCode << std::endl;
// prints 259, NOT 55
}
int _tmain(int argc, _TCHAR* argv[])
{
atexit(exithandler);
exit(55);
return 0;
}
This is for Windows, but I am looking for a solution for UNIX/Linux. BTW... this solution does NOT work because the process has not yet terminated when my exit handler is called, thus resulting in exitCode of 259 instead of 55. 259 on Windows means the process is still active.
Does anyone know if this can be done?
Use case: Imagine you have a library and you want to check if someone is calling exit with a particular code.