c++ - Looped signal handling for UNIX -


i have loop in main() continue until stop signal (ctrl z) or quit (ctrl ) obtained. loop:

signal(sigquit, signalhandler); signal(sigtstp, signalhandler); while (1)     sleep(1); 

what want when receive ctrl z signal, in addition printing out "stop received", want program stopped. current signal handler function:

void signalhandler(int signum) {     if (signum == sigquit)         cout << "quit recieved" << endl;         break;     else if (signum == sigtstp)         cout << "stop recieved" << endl;         break;     else {         cout << "something's wrong" << endl;         exit(-1);     }  } 

what need add in order me (this being stop signal received , stop program)? i've tried far putting raise(sigtstp) in signalhandler function, puts me in infinite loop. i've tried creating volatile sig_atomic_t, initializing 0, never updates me once signal received (it stays @ 0).


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -