Re: Launch a user-process from daemon
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=xlS/rEE4m6jHNZqn8xg8hw0T6VuYdaIVz2h3QhxQdq8=; b=MBI41ZMLIMWM6O6QBuc5B7Ry9JW2WH6TT2/VvczhannClShpF6GStmcxVPta0mdRrj zYOIm0PlTHt6Ol6gTQBPORMnNGUNi4mvuutSl6ilCgE3X9DHGPM85IWBo+uunqaPhy1H jiiuDF0dPjD6mhq9KLd8YrbI1QuAaDF59y790= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=ISKd7dhwv5w43hnWV+V+LPZRgfqrfewrtbB3mmU2Kvo5WYtU7zVzwy4fY0wxXSj0Gq X2ETcTdHjizWAveCz7B/3kMWS5Fn8VzaSz3RyoWjgxVtafKqV4u+wrjrG2TtopdIWX8k zb9QKF7pknZA/zQqNWu1um7IEahWMuCsifVpg= Jason Thanks. It think now GUI will not be terminated with non-gui process. Shawn thanks. I was using LaunchServices but I was facing 2 different issues. One is getting error -10810 and another passing of command line argument both in 10.4. LaunchServices was working properly with 10.5. Regards rksingal On Wed, Jan 28, 2009 at 12:07 AM, Jason Coco <jason.coco@gmail.com> wrote:
On Jan 27, 2009, at 13:22 , Rakesh Singhal wrote:
It is very simple. There is nothing like daemon and not related to usb device. One process is launching another GUI application thats all. Only to launch the GUI, I am looking for different APIs. Obviously I have to support both 10.4 and 10.5. 1. LSOpenApplication() 2. execl() 3. system()
Hi Rakesh,
You have to separate your process group from the original process group. When you get a kill signal, it's propagated to the entire process group, which is why your GUI application is terminating when your non-GUI process receives a kill signal. You have two basic ways you can do this. The daemon(3) library call will sever your process group, your tty connections and do other clean-up. If you only want to sever your process group, you can do something like this:
// Prepare to launch the new application pid_t pid = fork();
if( pid == 0 ) { // child process setsid(); // this will sever the relationship to the parent's process group and controlling terminal execl( "/Applications/TextEdit.app/Contents/MacOS/TextEdit", "/Applications/TextEdit.app/Contents/MacOS/TextEdit", NULL); // if the child gets here, an error occurred in execl(2) fprintf(stderr, "Error executing application: %s", strerror(errno)); return -1; }
// Original parent continues to do whatever it wants... it will now longer pass any signals to the newly loaded GUI image
In general, the call to setsid(2) can be replaced with daemon(3), although daemon(3) will do some other things, like change the directory and is really meant for a terminal-based application that wants to disassociate itself from its controlling terminal process (the call to daemon(3) includes the fork(2) call) and is, therefore, discouraged from use in favor of tools like launchd(8).
Jason
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Rakesh Singhal