Re: Trapping user shutdown/logout/restart in Cocoa/Foundation tool
Re: Trapping user shutdown/logout/restart in Cocoa/Foundation tool
- Subject: Re: Trapping user shutdown/logout/restart in Cocoa/Foundation tool
- From: "parag vibhute" <email@hidden>
- Date: Wed, 9 Jan 2008 19:21:27 +0530
Some observations:
1. I was launching cocoa application from terminal, in that case its parent
process was Terminal. So when I used to logout the machine, terminal process
was used to kill & so my application was also used to killed. Bcoz of this
application was not able to trap the logout(bcoz it is terminated).
2. Now in order to make launchd as parent process of my application, I wrote
a simple C program & then through it, I launched the application using
system API & using "&" at the end (for e.g.
system("./testapp/Contents/MacOS/testapp &");). Now when I checked in
activity monitor, parent process of my application was "launchd". More
interesting observation is now application was able to logout using
"workspaceWillPowerOff" notification. Please note that I did not use
daemon() API in my code while testing this.
3. Other way to make launchd as parent process of my appliation is using
daemon() API, but as you said I should never link daemon() API with
carbon/cocoa framework. So I think this is not preferred.
But I would like to know comments regarding point 2.
Thanks,
Palav
On Jan 9, 2008 1:40 PM, Jean-Daniel Dupas <email@hidden> wrote:
>
> Le 9 janv. 08 à 06:35, Andrew Farmer a écrit :
>
> > On 08 Jan 08, at 07:49, parag vibhute wrote:
> >> Thanks for reply. I have a requirement to run the application, not
> >> to show
> >> application icon in dock & to trap shutdown, restart, logout. As
> >> Jean-Daniel
> >> said, there are other ways to capture the logout,restart,shutdown.
> >> But it
> >> seems that those ways are particularly created for daemon otherwise
> >> in cocoa
> >> application, it is rarely that anybody will use those techniques for
> >> capturing logout/restart/shutdown; programmer will use
> >> workspaceWillPowerOff
> >> notification. Those techniques are particularly useful to
> >> differentiate
> >> between logout, restart & shutdown notification. I went through
> >> technote
> >> which you suggested, but for creating daemon, I will need to
> >> implement plist
> >> & I can't do that. I can only make changes in code of my
> >> application. I
> >> can't create plist & stuff like that. I read that in order to
> >> control the
> >> daemon by launchd, do not use "daemon" API. Also checked that if
> >> you launch
> >> the application in C program using system api & concating "&" at
> >> the end of
> >> path (like system "./testapp &"), application runs in background &
> >> its
> >> parent process become launchd. But it doesn't affect. Yes you are
> >> right that
> >> technote mention that do not link daemon to non-daemonized
> >> framework. But I
> >> think that statement is only concerned if you want to relate daemon
> >> to inetd
> >> or launchd etc. Using "daemon" API only in code does not make
> >> application
> >> daemon.
> >
> > TN2083 makes one thing quite clear: daemon() should not be used in
> > new applications, and particularly not in any application which uses
> > the Cocoa or CoreFoundation frameworks.
> >
>
> And that's not an issus, as daemon() is absolutly NOT required to use
> SystemConfiguration and IOKit frameworks. All information found in the
> previous Q&A can be used in the middle of an Objc Class in a Cocoa
> application without
> problem._______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
--
There are many things in your life that will catch your eye but only a few
will catch your heart....pursue those'.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden