Thread: handle_interrupts--->SIGBREAK

  1. #1
    Registered User
    Join Date
    Jul 2005


    Originally, SIGBREAK is handled in my program --->

    signal( SIGBREAK, (_SigFunc)handle_interrupts );
    void handle_interrupts( int code )
        printf( "%d Signal received. Shutting down...\n", code );
        fflush( stdout );
        logError( "%d Signal received. Shutting down...", code );
        bShutdown = 1;
    But i found that SIGBREAK is raised when a user logs off from Windows. But it is not expected to be shutdown in this situation.
    Then i remark it---->

    //signal( SIGBREAK, (_SigFunc)handle_interrupts );

    Then this problem is solved, but another problem raised:
    When user restarts windows during using my program, it is not handled well. Since my program is about TCP/IP, in the above case, the resources cannot be released. Q is:
    1. Is "ctrl-break" triggered by "windows shutdown"?
    2. If so, how can I distinguish "windows shutdown" and "user logs off" when there is a "Ctrl-break" exception?
    Last edited by n4247558; 07-06-2005 at 01:40 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    I think you need to work your program into being a windows program rather than a console program.

    Then you'll get access to all the windows events which tell you things like user logged off or shutdown in progress.
    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