lab3-ex-v2

lab3-ex-v2 - // the signal handler for handling SIGINT void...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* A more portable version. This is defined by the POSIX standard (an excerpt from the man-page): When a signal is caught by a signal-catching function installed by sigaction(), a new signal mask is calculated and installed for the duration of the signal-catching function (or until a call to either sigprocmask() or sigsuspend() is made). This mask is formed by taking the union of the current signal mask and the value of the sa_mask for the signal being delivered unless SA_NODEFER or SA_RESETHAND is set, and then including the signal being delivered. If and when the user's signal handler returns normally, the original signal mask is restored. */ #include <unistd.h> #include <signal.h> #include <stdio.h> #include <iostream> #include <sys/types.h> using namespace std;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // the signal handler for handling SIGINT void handle_INT(int num) { if ( 2 == num ) cout<< "Signal received--SIGINT"<<endl; return; } // the signal handler for handling SIGQUIT void handle_QUIT(int num) { if (3 == num) cout << "Signal received--SIGQUIT" << endl; return; } int main() { struct sigaction sa; int pi; pi=getpid(); cout<<"Process id is "<<pi<<endl; /* use sigaction to install a signal handler */ sigaction(SIGINT, NULL, &sa); sa.sa_handler = handle_INT; sigaction(SIGINT, &sa, NULL); //for SIGINT sigaction(SIGQUIT, NULL, &sa); sa.sa_handler = handle_QUIT; sigaction(SIGQUIT, &sa, NULL); //for SIGQUIT // an endless for loop; have to be killed by "kill -9" for(;;) { cout<<"No signal!"<<endl; sleep(1); } return 0; }...
View Full Document

This note was uploaded on 12/01/2010 for the course CS 2342 taught by Professor Dr during the Spring '10 term at HKU.

Page1 / 2

lab3-ex-v2 - // the signal handler for handling SIGINT void...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online