linux - C: Trying to restore signal handlers with sigaction but not succeeding. -


i'm writing small program in c, (running on ubuntu). first time program receives ctrl+c, want signal ignored, second time (after 10 seconds of waiting), want original action restored (and signal not ignored). have this:

void (*sold)(int); struct sigaction s; sold = s.sa_handler; s.sa_handler = sig_ign; sigaction(sigint,&s,null); sleep(10) s.sa_handler = sold; //(this replaced s.sa_handler = *sold , doenst make difference) 

the program seems ignore sigint fine, doesn't revert back.., in doesn't restore old handler. doing wrong?

if want restore old signal handler, need save , restore old handler:

struct sigaction newhandler; struct sigaction oldhandler; memset(&newhandler, 0, sizeof(newhandler)); sigemptyset( &newhandler.sa_mask ); newhandler.sa_handler = sig_ign; sigaction(sigint, &newhandler, &oldhandler ); sleep( 10 ); sigaction(sigint, &oldhandler, null ); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -