• 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: hung in read$UNIX2003
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: hung in read$UNIX2003


  • Subject: Re: hung in read$UNIX2003
  • From: Ken Thomases <email@hidden>
  • Date: Fri, 3 Apr 2009 13:42:52 -0500

On Apr 3, 2009, at 11:10 AM, Michael Ash wrote:

On Fri, Apr 3, 2009 at 9:36 AM, Michael Domino
<email@hidden> wrote:

I have a task prepared and launched with the code below, and when it returns
(in this situation that status code returned from terminationStatus is 0),
it hangs in availableData, never to return. [...]


messagePipeError = [NSPipe pipe];
messagePipeOutput = [NSPipe pipe];
[task setLaunchPath:@"/usr/bin/ hdiutil"];
[task setArguments:[NSArray
arrayWithObjects:@"info", nil]];
[task setStandardError:messagePipeError];


[task setStandardOutput:messagePipeOutput];

                               [task launch];
                               [task waitUntilExit];
                               status = [task terminationStatus];

NSData *messageDataError = [[messagePipeError
fileHandleForReading] availableData];
messageError = [[[NSString alloc]
initWithData:messageDataError encoding:NSUTF8StringEncoding] autorelease];

I don't know if this is the cause of your problem or not, but never, ever do this. Don't call waitUntilExit before you read. Pipes have a small buffer (4kB?) and if it fills up then further writes will block. This means that if you do a waitUntilExit while the subprocess is writing more data than the pipe can buffer, you'll deadlock. The subprocess will be waiting for you to read data before it can continue, and you will be waiting for it to exit before you read data. Read all data (using readDataToEndOfFile or equivalent) *before* you do waitUntilExit.

And, since you have two pipes, you're going to have to read from both simultaneously. Otherwise, you still have a chance for deadlock, if you're blocking reading on one handle while the subprocess is blocking waiting for the other pipe to be drained.


This is best done using the asynchronous methods of NSFileHandle.

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


  • Follow-Ups:
    • Re: hung in read$UNIX2003
      • From: Michael Ash <email@hidden>
References: 
 >hung in read$UNIX2003 (From: Michael Domino <email@hidden>)
 >Re: hung in read$UNIX2003 (From: Michael Ash <email@hidden>)

  • Prev by Date: Re: Dismissing the iPhone keyboard
  • Next by Date: RE: IB Plugin help
  • Previous by thread: Re: hung in read$UNIX2003
  • Next by thread: Re: hung in read$UNIX2003
  • Index(es):
    • Date
    • Thread