Look at the sources. It uses kevent. (man kevent)

Le 31 mars 2010 à 14:24, McLaughlin, Michael P. a écrit :

> How does WatchForTermination() do its watching?  Is it constantly polling?  
> That would be a performance-killer.
> 
> 
> On 3/30/10 11:18 PM, "John Harte" <johnha...@mac.com> wrote:
> 
> 
> 
> On Mar 30, 2010, at 4:01 PM, McLaughlin, Michael P. wrote:
> 
>> I have a Cocoa app (Leopard) which launches several Foundation Tool subtasks
>> (since threads are not sufficient in this case).  Currently, I terminate
>> these subtasks via the app-delegate method
>> 
>> -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication
>> *)sender
>> 
>> This works provided one Quits the main app using the Quit menu item.
>> However, if I force-quit or if I abort using the Stop icon in Xcode, then
>> the main app terminates without terminating the subtasks.
>> 
>> Is there a more reliable hook (e.g., delegate method) that would always get
>> called even on force-quit or Stop from Xcode so that these subtasks would
>> always get terminated?  [Otherwise, I have to terminate them from Activity
>> Monitor.]
>> 
> 
> I use kqueue in the child process. Kick off a thread and wait for the parent 
> to terminate.
> 
> 
> int main (int argc, char* const argv[]) {
>        // Start a thread to watch for parent termination
>        pthread_t thread;
>        int error = pthread_create (&thread, 0, WatchForTermination, 0);
>       .
>       .
>       .
> 
> void* WatchForTermination (void* arg) {
>        pid_t ppid = getppid ();        // get parent pid
> 
>        int kq = kqueue ();
>        if (kq != -1) {
>                struct kevent procEvent;        // wait for parent to exit
>                EV_SET (&procEvent,             // kevent
>                                ppid,                   // ident
>                                EVFILT_PROC,    // filter
>                                EV_ADD,                 // flags
>                                NOTE_EXIT,              // fflags
>                                0,                              // data
>                                0);                             // udata
> 
>                kevent (kq, &procEvent, 1, &procEvent, 1, 0);
>        }
>        printf ("Terminating--Parent Process Terminated\n");
>        exit (0);
>        return 0;
> }
> 
> 
> 
> 
> --
> Mike McLaughlin
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/devlists%40shadowlab.org
> 
> This email sent to devli...@shadowlab.org

-- Jean-Daniel




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to