c - SIGTSTP signal handler to ignore/act on SIGTSTP based on condition -
like question says, want handle sigtstp signal differently based on conditions. final code won't simple i'm trying work first:
class="snippet-code-js lang-js prettyprint-override">static void stphandler(int signo) { sigset_t mask; //unblock sigtstp sigemptyset( & mask); sigaddset( & mask, sigtstp); sigprocmask(sig_unblock, & mask, null); if (getpid() != ultimateparent) { printf("not parent process\n"); exit(0); } else { printf("this parent process"); } }
code on parent process initialization:
ultimateparent=getpid(); sa_stp.sa_handler = stphandler; sigemptyset(&sa_stp.sa_mask); sa_stp.sa_flags = sa_restart; sigaction(sigtstp, &sa_stp, null); code create child:
//leave args blank. maintain wc waiting input execerr=execvp("wc",args); if(errno==eacces) { fprintf(stderr,"%s: permission denied.\n",command); } else { fprintf(stderr,"%s: command not found.\n",command); } exit(0); here did , output got:
in parent:
when parent running , nail ctrl+z output is: ^z
when nail homecoming key, printf command executes on next line:
"this parent process"
question: why wait me nail homecoming key proceed?
in child
it prints ^z many times generate signal, goes next line homecoming key- ignores ctrl+d (which cause wc read eof , finish execution) or other signal matter, besides sigquit.
question: why ignore farther signals after ctrl+z? there way create kid exit instead?
i sense i'm missing important signals , signal handlers in general. help, articles or other references appreciated.
c unix signals
No comments:
Post a Comment