• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Terminating subtasks reliably
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Terminating subtasks reliably


  • Subject: Re: Terminating subtasks reliably
  • From: Julian Hsiao <email@hidden>
  • Date: Sat, 3 Apr 2010 04:20:21 -0700

Why not have the parent call setsid() / setpgid() at the beginning?  This should prevent the PID from getting recycled until every process in the process group exits.

Julian Hsiao
email@hidden

On Apr 2, 2010, at 8:10 PM, Michael Ash wrote:

> On Thu, Apr 1, 2010 at 7:19 PM, Dave Keck <email@hidden> wrote:
>>>> Look like a race condition. The man page says getppid() will not fail, but
>>>> not what happens after the parent dies. I will test this.
>>>
>>> If the parent dies, the process becomes the child of launchd. For a quick
>>> fix I checked for the parent PID greater than 1.
>>>
>>> A better fix, the parent process passed its PID to the child process as an
>>> argument. In the child process, if getppid() does not return the PID from
>>> the parent process, exit.
>>
>> Another problem is if the parent dies after the getppid(), and another
>> process starts with the same PID as the old parent, all before the
>> call to kevent(). In this scenario you'll now be waiting for an
>> unrelated process to die. This situation is likely impossible
>> currently with incrementing PIDs, but there's been mention of PID
>> randomization on darwin-dev:
>>
>>    http://lists.apple.com/archives/darwin-dev/2009/Oct/msg00056.html
>>
>> I only mention this because I use this kevent method to detect a
>> parent's death, and have been looking for a better technique that
>> also doesn't require the parent's cooperation...
>
> Call getppid, set up the kevent listener, then before you actually
> block in kevent, call getppid *again*. If the answer matches the first
> call, then you can go ahead and call kevent. If the answer doesn't
> match, you've hit the race condition you outline here, your parent is
> dead, and you can exit immediately. If the parent quits after the
> second getppid but before the call to kevent, you should still get the
> exit notification because you registered it before the parent quit.
>
> Mike
_______________________________________________

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

  • Follow-Ups:
    • Re: Terminating subtasks reliably
      • From: Scott Ribe <email@hidden>
References: 
 >Re: Terminating subtasks reliably (From: Dave Keck <email@hidden>)
 >Re: Terminating subtasks reliably (From: Michael Ash <email@hidden>)

  • Prev by Date: Re: How do I get a file reference w/o relying on the path?
  • Next by Date: Multi Window cocoa application
  • Previous by thread: Re: Terminating subtasks reliably
  • Next by thread: Re: Terminating subtasks reliably
  • Index(es):
    • Date
    • Thread