lab3-ex-v1

lab3-ex-v1 - instances of the signal are blocked from being...

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

View Full Document Right Arrow Icon
/* This program is working perfectly under Linux (with recent distributions). However, is not working as what we expected under Solaris. Reason (an excerpt from the man-page): "In the original Unix systems, when a handler that was established using signal() was invoked by the delivery of a signal, the disposition of the signal would be reset to SIG_DFL, and the system did not block delivery of further instances of the signal. System V also provides these semantics for signal(). This was bad because the signal might be delivered again before the handler had a chance to reestablish itself. Furthermore, rapid deliveries of the same signal could result in recursive invocations of the handler. BSD improved on this situation by changing the semantics of signal handling (but, unfortu- nately, silently changed the semantics when establishing a handler with signal()). On BSD, when a signal handler is invoked, the signal disposition is not reset, and further
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: instances of the signal are blocked from being delivered while the handler is executing." Recent versions of Linux adopted the BSD style, while Solaris is using the System V style. It is recommended to use sigaction() instead. */ #include <unistd.h> #include <signal.h> #include <stdio.h> #include <iostream> #include <sys/types.h> using namespace std; // 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() { int pi; pi=getpid(); cout<<"Process id is "<<pi<<endl; // install the signal handlers signal(SIGINT, handle_INT); signal(SIGQUIT, handle_QUIT); // an endless for loop; have to be killed by "kill -9" for(;;) { cout<<"No signal!"<<endl; sleep(1); } return 0; }...
View Full Document

Page1 / 2

lab3-ex-v1 - instances of the signal are blocked from being...

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