handle_interrupts--->SIGBREAK

This is a discussion on handle_interrupts--->SIGBREAK within the Windows Programming forums, part of the Platform Specific Boards category; Originally, SIGBREAK is handled in my program ---> Code: /*.... ... .../ signal( SIGBREAK, (_SigFunc)handle_interrupts ); /*.... ... .../ void ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    1

    handle_interrupts--->SIGBREAK

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

    Code:
    /*....
    ...
    .../
    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.
    So.......my 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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21