Re: Weirdness in my PowerBook... Now reproducible
Re: Weirdness in my PowerBook... Now reproducible
- Subject: Re: Weirdness in my PowerBook... Now reproducible
- From: "Michael Ash" <email@hidden>
- Date: Mon, 3 Apr 2006 00:23:21 -0500
On 4/2/06, Jerry Krinock <email@hidden> wrote:
> If no one here can explain this mess, I'll go find some Unix geeks to
> consult with. But not for a few days because, now that I can reproduce it,
> I have some other more pressing issues needing attention. I'll let y'all
> know whenever I get some understanding of this.
I am almost 100% sure that the problem is the following:
You're doing [task waitUntilExit] before you read the data out of the
task's output pipe. This is wrong and will fail exactly as you've
described. The problem is that an NSPipe is just a thin wrapper around
a UNIX pipe. UNIX pipes are kernel-level constructs which have a small
fixed size. When they're full, the writer will block until the reader
removes some data from it. This means that the following will fail
just as you've described:
[task launch];
[task waitUntilExit];
NSData *data = [[[task standardOutput] fileHandleForReading]
readDataToEndOfFile];
As soon as the subprocess's output exceeds the size of the pipe (which
is typically around 4k) then the subprocess will block, waiting for
the parent to read. The parent is waiting for the subprocess to exit.
Deadlock.
This is easily fixed by simply switching the order of the statements:
[task launch];
NSData *data = [[[task standardOutput] fileHandleForReading]
readDataToEndOfFile];
[task waitUntilExit];
In fact, the last line is entirely superfluous, since you only care
about getting all data, and the actual termination of the subprocess
is something you don't care about directly.
And of course having more running processes will generate more data
from ps, which explains why the problem only appears when "too many"
processes are running. And of course uuidgen works fine because it
never generates very much output. (Of course, the fact that this works
is an implementation detail and should never be relied on.)
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden