• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: cocoa-dev digest, Vol 1 #731 - 16 msgs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cocoa-dev digest, Vol 1 #731 - 16 msgs


  • Subject: Re: cocoa-dev digest, Vol 1 #731 - 16 msgs
  • From: Brian Hill <email@hidden>
  • Date: Wed, 17 Oct 2001 18:39:08 -0500

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


  • Follow-Ups:
    • Re: cocoa-dev digest, Vol 1 #731 - 16 msgs
      • From: Jason Bobier <email@hidden>
References: 
 >Re: cocoa-dev digest, Vol 1 #731 - 16 msgs (From: Jason Bobier <email@hidden>)

  • Prev by Date: Re: nobody knows, or just can't be done?
  • Next by Date: Re: Ownership of nib instances
  • Previous by thread: Re: cocoa-dev digest, Vol 1 #731 - 16 msgs
  • Next by thread: Re: cocoa-dev digest, Vol 1 #731 - 16 msgs
  • Index(es):
    • Date
    • Thread