06-19-2009, 10:28 AM #1
relaunch an application in OS X Leopard
- Member Since
- Jun 19, 2009
I have an application (in C/C++, Carbon) which occasionally downloads itself from an FTP server to the Applications folder (the original application is renamed to .bak). Now I want to relaunch this new version. How can I do that? I have tried following:
1. if the application wants to restart itself, then right before the end of main(), I do execlp("sh", "sh", "-c", "open -a /Applications/MyApp.app", 0);
This doesn't work as soon as I use a socket() call in the application, which I necessarily have to use to download the new version. It doesn't work on both OS X Tiger and Leopard. If I don't use the socket(), it works fine.
2. I tried to fork() and let the child do all the work (GUI and download). The parent waits for the child and if the child exits with return code 42, it does the execlp() to restart. This doesn't work because after the fork() the child actually can't use core-foundation on Leopard.
3. the application does all the work (GUI and download). If it wants to restart, I do fork() and in the child I do execlp(). This works on Tiger but not on Leopard. The same with vfork().
4. so I though fork() after all the work is done is too late. The application first does the fork(). The parent does all the work. The child just waits (read from stdin (0)). When the app wants to restart, the parent kills the child with SIGUSR1 otherwise it kills the child with SIGTERM. The child handles SIGUSR1 and in the handler it execlp() itself. This works on Tiger but not on Leopard.
5. actually should be point 0. I tried the launch services to launch the app, but it doesn't work, because the OS finds that the application is already running, and thus it doesn't re-launch it.
Currently I just show a message telling "new version downloaded, pls restart". Is there a way to re-launch "itself"?
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
By ActiveLight in forum OS X - Operating SystemReplies: 3Last Post: 06-28-2012, 06:04 PM
By kbeatty in forum OS X - Operating SystemReplies: 4Last Post: 01-06-2010, 07:21 PM
By deReggi in forum OS X - Apps and GamesReplies: 2Last Post: 06-16-2009, 02:09 PM
By schweb in forum News and Community AnnouncementsReplies: 1Last Post: 05-19-2009, 05:26 PM
By snowkid2themax in forum Apple DesktopsReplies: 0Last Post: 04-20-2009, 04:26 PM