Thread: How to identify that user has terminated the program

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    4

    How to identify that user has terminated the program

    Hi
    I am using visual studio 2005 .

    The following code works fine if there is a abort internal to the program.

    I want to know is there any API or signal by using which I can know that user of the program has abnormally terminated the program.

    Case 1: The user clicks the close button of the IDE.

    Case 2: The user uses the Stop Debugging button to kill the process.

    Code:
    void SignalHandler(int signal)
    {
    	do{  
    	printf("Application aborting...\n");
    	}while(1);
    }
    
    int main()
    {
        int i = 100;
    typedef void (*SignalHandlerPointer)(int);
    
     SignalHandlerPointer previousHandler;
     previousHandler = signal(SIGABRT, SignalHandler);
    abort();
    
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    I think you're looking for SIGTERM
    Last edited by robwhit; 07-11-2007 at 04:47 PM.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Case 1: The user clicks the close button of the IDE.
    > Case 2: The user uses the Stop Debugging button to kill the process.
    I thought the code being debugged never gets to see either of these. It's strictly a "do not pass go, do not collect $200" deal.

    Sure, when you're running the program for real, then you may get various messages / signals (depending on your OS) when the program exits by various means.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 08-23-2008, 07:44 AM
  2. user input and program design
    By Chaplin27 in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2005, 08:53 AM
  3. Instant messenger app help
    By AusTex in forum C Programming
    Replies: 2
    Last Post: 05-01-2005, 12:41 AM
  4. Enistine program
    By Mac_the vamp in forum C Programming
    Replies: 2
    Last Post: 11-11-2002, 10:56 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM