Re: Inter process communication question
Re: Inter process communication question
- Subject: Re: Inter process communication question
- From: Terry Glass <email@hidden>
- Date: Wed, 5 Feb 2003 06:05:17 -0600
On Tuesday, February 4, 2003, at 09:04 PM, Frank Fenn wrote:
>
Hi all,
>
>
I've a daemon like tool running at startup time from
>
/Library/Startupitems. Now I would like to
>
to communicate with this process from a preferences panel. Since I
>
found in an earlier message
>
here, that NSDistributedNotification won't work as expected how can I
>
transmit or signal the
>
daemon process from the preferences program? I only need to signal 3
>
things: start, stop, and
>
restart.
>
>
Can I use BSD signals? NSPort, NSMachPort? Any tip for some example
>
code snippets would
>
be appreciated.
I feel that using distributed objects is overkill for your purposes. I
would suggest signals.
In main I add this:
// Install signal handler for SIGHUP
if(signal(SIGHUP, signalHandler) == SIG_ERR) {
NSLog(@"Failed to install signal handler for SIGHUP...
Exiting");
exit(1);
}
// Install signal handler for SIGTERM
if(signal(SIGTERM, signalHandler) == SIG_ERR) {
NSLog(@"Failed to install signal handler for SIGTERM...
Exiting");
exit(1);
}
Here's my signal handler:
static void signalHandler(int signalNumber)
{
if(signalNumber == SIGHUP) {
// Reload configuration
[[Daemon sharedInstance] restart];
} else if(signalNumber == SIGTERM) {
// Exit gracefully
unlink("/var/run/dynamicdnsd.pid");
exit(0);
}
}
I've read that the way I handle SIGHUP is bad, but I haven't run in to
any trouble yet. The best way to handle it that I've seen is to set a
global variable like BOOL gShouldRestart and poll it.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.