Launching scripts without fork

I'm working on a project at work that involves a daemon process launching scripts to do some configuration. Traditionally, this is done using fork/exec, as expected. However, the daemon uses CoreFoundation, which causes the program to be killed if the calls are made after a fork().

I've tried using LSOpenApplication() to launch the scirpts via Terminal, however this produces the undesirable situation of the Terminal GUI showing up while the script runs.

So this leads to the question, is there a way to launch background scripts safely? This method cannot make use of fork at all. Thanks in advance for any help.

MacBook, Mac OS X (10.5.6)

Posted on Mar 11, 2009 6:45 AM

Reply
3 replies

Mar 11, 2009 7:28 AM in response to orangekay

This is a strange issue that we have run into already.

CoreFoundation has a number of functions that cannot be used after calling fork(). These functions can only be safely used if the program calls an exec() after the fork(). Unfortunately, when the daemon calls fork() to create a child, it can't call exec() itself, leaving it in a state that is unable to use CoreFoundation functions.

See http://developer.apple.com/releasenotes/CoreFoundation/CoreFoundation.html under the header "CoreFoundation and fork()" for a little more information.

The result of this is that, because the daemon we have uses CoreFoundation, we can't use fork() to create child processes.

I'm trying to determine if there is a way to create background script processes without fork/exec for this reason. Otherwise, we will have to redesign the architecture to separate the Unix-based code from the OSX-based code to allow us to use fork/exec correctly.

Hopefully, this explanation is sufficient.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Launching scripts without fork

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.