• 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: continuing after fork() (Re: Problems with NSTimer and NSRunLoop/CFRunLoop)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: continuing after fork() (Re: Problems with NSTimer and NSRunLoop/CFRunLoop)


  • Subject: Re: continuing after fork() (Re: Problems with NSTimer and NSRunLoop/CFRunLoop)
  • From: Mont Rothstein <email@hidden>
  • Date: Thu, 13 Jan 2005 11:42:16 -0800

Chris and Kalein, thank you both.

-Mont

On Jan 13, 2005, at 11:21 AM, Chris Kane wrote:


On Jan 12, 2005, at 10:56 PM, Mont Rothstein wrote:


Thank you Chris for the detailed and informative reply, this problem has been haunting me for some time.

If you don't mind I'd like to clarify my interpretation of your response to make sure I have a handle on this.

First, since my last post I have determined that certain frameworks I was including cause my child to fail. Without those frameworks the child runs fine.

If I understand you correctly then the fact that without those frameworks the child works is luck, because in both cases the app links against Apple frameworks. I was headed down a path of attempting to remove the dependency on the problem frameworks (my previous removal was only a test and was at the expense of functionality). Given your description I believe I should abandon that course and instead use execve() because even the working version is at risk of failing.

That would be best. Though it is kind of a pain if you have to refactor the code, though most things I've seen do the fork() in main(), so they haven't gone too far in to execution.



Also, I am unclear from the man page on execve(). Will my parent process still receive the exit from the child? And it sounds like I need a second main() with (argc, argv, envp) that will be called by execve().

Yes. fork + execve is the typical operation for creating new processes, so that all works fine.


You don't need a second main(), you just augment your existing main() to look at the argument list or environment list (argv list is probably easier to work with) for a special argument/environment variable that means "this is the child process", and continue down a different code that that does not include reforking (or, set a boolean variable that the forking code later looks and and skips the fork and does the child thing instead).

Just declare main() like this if it isn't already: int main(int argc, const char *argv[])
and iterate over argv using strcmp() to compare each argument to your special one.


Creating the enhanced argument list to pass to execve() I'll let you work out. Just pass 'environ' for the environment argument.


Chris Kane Cocoa Frameworks, Apple



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Problems with NSTimer and NSRunLoop/CFRunLoop (From: Mont Rothstein <email@hidden>)
 >Re: Problems with NSTimer and NSRunLoop/CFRunLoop (From: John Stiles <email@hidden>)
 >Re: Problems with NSTimer and NSRunLoop/CFRunLoop (From: Brendan Younger <email@hidden>)
 >Re: Problems with NSTimer and NSRunLoop/CFRunLoop (From: John Stiles <email@hidden>)
 >Re: Problems with NSTimer and NSRunLoop/CFRunLoop (From: Brendan Younger <email@hidden>)
 >Re: Problems with NSTimer and NSRunLoop/CFRunLoop (From: Mont Rothstein <email@hidden>)
 >continuing after fork() (Re: Problems with NSTimer and NSRunLoop/CFRunLoop) (From: Chris Kane <email@hidden>)
 >Re: continuing after fork() (Re: Problems with NSTimer and NSRunLoop/CFRunLoop) (From: Mont Rothstein <email@hidden>)
 >Re: continuing after fork() (Re: Problems with NSTimer and NSRunLoop/CFRunLoop) (From: Chris Kane <email@hidden>)

  • Prev by Date: Problem with custom toolbar items on 10.2
  • Next by Date: Re: Bindings Book !!!!!
  • Previous by thread: Re: continuing after fork() (Re: Problems with NSTimer and NSRunLoop/CFRunLoop)
  • Next by thread: [SOLVED] Re: continuing after fork() (Re: Problems with NSTimer and NSRunLoop/CFRunLoop)
  • Index(es):
    • Date
    • Thread