Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

How to block and unblock the ctrl-c singal in my windows application?

$
0
0

Hi,

I am having a use case where I want to block the ctrl-c signal generated by console application for doing some processing and then after the processing is done I would like to continue with the program by handling the ctrl-c signal handler.

I am able to do this successfully on UNIX platfroms by using

sigprocmask(SIG_BLOCK   and

sigprocmask(SIG_UNBLOCK, But i am not able to do the same on windows platform.

For implementing the same on windows i am using below logic:

 signal(SIGINT, signal_handler); // To register the signal with the program
 if( SetConsoleCtrlHandler( NULL, TRUE ) == 1) // this will disable the signal handler
  { 
  Sleep(5000);
  } else {
   printf("failed to disable the signal handler.\n");
  }

if( SetConsoleCtrlHandler( NULL, FALSE ) ){ // this will enable the signal handler after the sleep is over
  Sleep(5000);
}

Here the issue I am facing is if user presses ctrl-c before the  disabling the singal handler, then in that case the ctrl-c signal is getting ignored and I am missing it. So when the program comes back to signal handler by enabling it, then we are missing the signal.

I would like to know if there is any way in windows we can block and unblock the signals.

Any help will be really appreciated.

Thanks,

Sushil


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>