|
Home > Archive > Unix Programming > September 2007 > Doubt regarding signal handlers
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Doubt regarding signal handlers
|
|
|
| Hi,
I have 2 processes running (P1, P2)
I want to write a signal handler in P2, to handle the signal SIGUSR1.
I heard that signal handlers should be as minimal as possible...
But, my requirement is to start an QT event loop when the signal is
received frm P1, that event loop will be running until an event
occurs.
So please let me know the signal handler for the signal SIGUSR1, can
be a big one...
if that should not please suggest a solution to my problem.
Note: My process shouldnt have any threads.
Please reply me ASAP.
Thanks in advance.
| |
| Ian Collins 2007-09-14, 7:32 am |
| kiran wrote:
> Hi,
>
> I have 2 processes running (P1, P2)
> I want to write a signal handler in P2, to handle the signal SIGUSR1.
> I heard that signal handlers should be as minimal as possible...
Good practice.
> But, my requirement is to start an QT event loop when the signal is
> received frm P1, that event loop will be running until an event
> occurs.
>
> So please let me know the signal handler for the signal SIGUSR1, can
> be a big one...
> if that should not please suggest a solution to my problem.
>
> Note: My process shouldnt have any threads.
>
Why?
One solution is to install an empty handler, enter a blocking system
call and wait for the signal to interrupt the call.
Something like
#include <poll.h>
#include <signal.h>
#include <errno.h>
void f() {}
int main(void) {
struct sigaction act;
act.sa_handler = f;
act.sa_flags = 0;
sigaction( SIGUSR1, &act, NULL );
struct pollfd fd;
int n = poll( &fd, 1, -1 );
if( errno == EINTR ) {
/* do your stuff */
}
}
--
Ian Collins.
| |
| Casper H.S. Dik 2007-09-14, 7:32 am |
| kiran <edu.mvk@gmail.com> writes:
>So please let me know the signal handler for the signal SIGUSR1, can
>be a big one...
No.
>if that should not please suggest a solution to my problem.
Set a flag and check that in your main loop.
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
|
|
|
|
|