Friday, April 20, 2012

using signal handler for ctrl-c - need help on infinite loops

I am using signal handler for ctrl-c signal. i.e whenever ctrl-c signal is generated instead of exiting the application I do some action.



Let us suppose if my application hangs due to while(1) loop (any error condition) is it possible for me to exit application only in that case?



ex:



void handle()
{
/*do some action*/
----
----
---

if ( while(1) detected)
{
exit(0);
}
}


main()
{
struct sigaction myhandle;
myhandle.sa_handler = handle;
sigemptyset(&myhandle.sa_mask);
myhandle.sa_flags = 0;
sigaction(SIGINT, &myhandle, NULL);

while(1);
}


Thanks





No comments:

Post a Comment