• 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: Ending NSTask doesn't release file handle opened by the task it wraps.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ending NSTask doesn't release file handle opened by the task it wraps.


  • Subject: Re: Ending NSTask doesn't release file handle opened by the task it wraps.
  • From: Graham Cox <email@hidden>
  • Date: Fri, 22 Jul 2016 11:44:04 +1000

> On 22 Jul 2016, at 9:22 AM, Uli Kusterer <email@hidden> wrote:
>
> On 21 Jul 2016, at 17:20, Graham Cox <email@hidden> wrote:
>> One of my apps uses NSTask to wrap a command line utility that is embedded in the same app’s resources. This utility writes files to disk - I have no knowledge of which APIs it uses to do this. If the task has ended (and I can see that the actual instance of the running command line tool has disappeared from my process tasks in Activity Monitor), and I send the file to the trash, I can’t delete it (empty trash) until the app as a whole is quit - I get the message that the file is still in use.
>>
>> I’ve checked that I’m closing down the NSTask properly, as far as I can see.
>>
>> Is this the expected behaviour?
>
> Are you reading all the data from the task (i.e. its standardOutput, not the file) before you close it? AFAIR that's a prerequisite for it to properly close.



I have a NSPipe attached to stdout. I’m not currently doing anything when the task termination handler is invoked to read from that, but it’s easy enough to do.

However, on further investigation, the problem doesn’t seem to be that.

Using lsof, I discovered that the process that was keeping the file open was indeed the command line tool I’m running with NSTask. But what was weird is that the processes that were keeping the file were running as a child process of Dock, not of my app, and were still running. Other instances of the process were running correctly as a child process of my app, and they don’t exhibit the problem, and of course go away when my app quits.

So what would cause a NSTask I create in my app to make the process it launches a child of Dock, not of my app?

—Graham



_______________________________________________

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


References: 
 >Ending NSTask doesn't release file handle opened by the task it wraps. (From: Graham Cox <email@hidden>)
 >Re: Ending NSTask doesn't release file handle opened by the task it wraps. (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: Ending NSTask doesn't release file handle opened by the task it wraps.
  • Next by Date: NSImage from bitmap - then delete bitmap
  • Previous by thread: Re: Ending NSTask doesn't release file handle opened by the task it wraps.
  • Next by thread: unexpected NSTextViewDelegate behavior
  • Index(es):
    • Date
    • Thread