Re: cocoa-dev digest, Vol 1 #731 - 16 msgs
Re: cocoa-dev digest, Vol 1 #731 - 16 msgs
- Subject: Re: cocoa-dev digest, Vol 1 #731 - 16 msgs
- From: Jason Bobier <email@hidden>
- Date: Wed, 17 Oct 2001 17:18:17 -0700
Hey Brian,
Actually, our service is being started with a Startup script at boot.
After further testing, it indeed appears to be a problem with using
NSDefaultRunLoopMode. Our engineer tried using a different runloop mode
and the service didn't get shutdown at logout.
So I guess the next question is, what ports does NSDefaultRunLoopMode
contain by default? If I was to guess, I would say that it connects to a
couple of ports (such as the window server) the first time that it is
used.
Thanx,
Jason
On Wednesday, October 17, 2001, at 04:39 PM, Brian Hill wrote:
On Wednesday, October 17, 2001, at 05:20 PM, Jason Bobier wrote:
I wonder why our loop gets shutdown then. Does NSDefaultRunLoopMode
automatically connect to the WindowServer?
It probably has to do with who the 'parent process' of your server is.
If you start a CLI application via Terminal, for example, even if it
has no run loop or GUI, it's parent process is Terminal. When Terminal
wants to quit, it will kill off all of it's child processes.
If you want to do the equivalent of 'nohupping' your sub-process
programmatically, you need to 'divorce' it from it's controlling TTY,
so that it doesn't get killed when it's parent process wants to quit.
Here's one incantation to do this:
BOOL daemonizeProcess()
{
BOOL isDaemon = NO;
pid_t pid;
chdir("/"); //give up any claims on the user's home dir, for example
freopen("/dev/null","r", stdin); //plug up stdin
freopen("/dev/console","a", stdout); //switch stdout to something
that can stay open
freopen("/dev/console","a", stderr); //switch stderr to something
that can stay open
switch(pid = fork())
{
case 0:
isDaemon = YES;
setsid(); //this is the important step to 'detach' from the
parent process
break;
default:
isDaemon = NO;
return isDaemon;
break;
}
return isDaemon;
}
int main (int argc, const char *argv[])
{
if(!daemonizeProcess())
{
sleep(1);
exit(0);
}
//else we're a daemon now
//start runloop, etc...
}
Brian
email@hidden http://personalpages.tds.net/~brian_hill
"Why? I came into this game for adventure - go anywhere, travel
light, get in, get out, wherever there's trouble, a man alone.
Now they've got the whole country sectioned off and you can't
move without a form. I'm the last of a breed."
-- Archibald "Harry" Tuttle, Rogue HVAC Repairman
--
Jason A. Bobier
email@hidden
Tech Lead, PGP Macintosh Products
http://www.prismatix.com/
Network Associates, Inc. Nothing's constant
PGPKey: <
http://keys.pgp.com:11371/pks/lookup?op=get&search=0xF6F83318>
Fingerprint: 7809 7E6E BCCA 903D 4618 9740 EB10 9DF9 F6F8 3318