Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Catching exit c...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 10 Topic 45813 of 45898
Post > Topic >>

Catching exit code before program termination

by titanandrews <titanandrews@[EMAIL PROTECTED] > May 8, 2008 at 09:05 AM

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:

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.




 10 Posts in Topic:
Catching exit code before program termination
titanandrews <titanand  2008-05-08 09:05:09 
Re: Catching exit code before program termination
Sam <sam@[EMAIL PROTEC  2008-05-08 11:34:36 
Re: Catching exit code before program termination
Sam <sam@[EMAIL PROTEC  2008-05-08 11:44:26 
Re: Catching exit code before program termination
Martin York <Martin.Yo  2008-05-08 11:30:47 
Re: Catching exit code before program termination
titanandrews <titanand  2008-05-08 12:47:53 
Re: Catching exit code before program termination
Rolf Magnus <ramagnus@  2008-05-08 23:28:02 
Re: Catching exit code before program termination
Joe Greer <jgreer@[EMA  2008-05-08 22:15:22 
Re: Catching exit code before program termination
titanandrews <titanand  2008-05-08 17:36:08 
Re: Catching exit code before program termination
Jerry Coffin <jcoffin@  2008-05-10 22:29:34 
Re: Catching exit code before program termination
kasthurirangan.balaji@[EM  2008-05-08 22:08:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 6:43:57 CDT 2008.