Alexander Reichstadt
[EMAIL PROTECTED]



On 15.04.2008, at 13:29, Ken Thomases wrote:

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

I tried both ways separately and in combination, terminate and kill, with kill I tried it with all signals available. I don't need to reboot, they do get reaped. Whether I waitUntilExit or not makes no difference, I also registered for the notification.

In Tiger NSTimer causes some problems in this context, so I resorted to detaching a thread. Upon your suggestion I reviewed this option now for Leopard using an NSTimer calling a method spawning the process with the tool using some sandbox app and it doesn't seem to cause this problem; even in cases where there is a zombie it always seems to expires permanently with the NSTimer instance. So thanks, I rewrite everything using timers.

Regards

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to