Re: App fails to kill NSTask processes
Re: App fails to kill NSTask processes
- Subject: Re: App fails to kill NSTask processes
- From: Ken Thomases <email@hidden>
- Date: Tue, 15 Apr 2008 06:29:32 -0500
On Apr 15, 2008, at 5:55 AM, Alexander Reichstadt wrote:
my app makes heavy use of NSTask. The tool it nstasks oftentimes
falls asleep and doesn't return, I can't fix it cause I don't have
the source code.
Til Tiger I worked around this behavior by making a custom class
that contains an NSTask and a thread, run the task, and let the
thread sleepUntilDate for a few seconds, then have the thread check
on the task and if it is dead kill it. That worked fine. But ever
since Leopard that doesn't work any more, neither main thread nor
any other thread can terminate the task or sigkill it, it continues
hanging around in the system. Only when I quit the app, it being
the ppid of all the dead processes, does it take the dead processes
with it. How can I kill those processes in Leopard?
There's quite a bit left unsaid in the above. How do you kill it?
Do you use kill(2) or -[NSTask terminate]? If the former, what
signal are you sending?
What does "ps" show as the status of the process? See the ps man
page for a description of some of these. It is possible for a
process to get stuck in the "Exiting" state, but in that case only a
reboot usually fixes it. That doesn't sound like the symptom you're
seeing. It sounds like your child processes are ending up as zombies
waiting to be reaped by the parent. I would expect Cocoa to take
care of that for you. However, it may be waiting for you to call -
[NSTask waitUntilExit]. Are you ever calling that?
Are you registering for the NSTaskDidTerminateNotification? If so,
are you seeing it being delivered?
After you kill the task, do you keep the NSTask object around, or are
you releasing it?
Lastly, as an aside, it seems like massive overkill to spawn a thread
to monitor each task. You can launch the task from the main thread
and use an NSTimer to schedule an occasional check if it's still alive.
Cheers,
Ken
_______________________________________________
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