Re: The thread that starts by NSTask didn't clear up
Re: The thread that starts by NSTask didn't clear up
- Subject: Re: The thread that starts by NSTask didn't clear up
- From: "Xianyu Ge" <email@hidden>
- Date: Thu, 11 Dec 2008 09:42:57 +0800
I appreciate that you give me you hand, Thank you very much, I have solved
this questions, and I also learn knowledge that NSTask is just a wrapper
around execve(), no threading involved. Thanks.
2008/12/10 Etienne Guérard <email@hidden>
> OK
> It seems that in leopard NSTask uses a thread to monitor the launched
> process, presumably to detect process termination. This thread should
> disappear shortly after the corresponding NSTask instance is released.
>
> Since the launched NSTask is auto-released you need to do one of the
> following:
> 1. Install a NSAutoreleasePool somewhere in your loop
> 2. Use [[NSTask alloc] init] and explicitly release your task when you're
> done.
>
> EG
>
>
> On Dec 10, 2008, at 11:02 AM, Xianyu_Ge wrote:
>
> hi, EG,
>> Thanks for you help. I had use threadViewer to note thread count,
>> when go to step that launch application use NSTask, thread count will
>> added, when application quit, the thread didn't stopped, but on tiger this
>> works right I think. I copy some codes as follows:
>>
>> NSMutableArray* args = [[[NSMutableArray alloc] init] autorelease];
>> NSString* ips = [NSString stringWithCString : ipAddress];
>> NSString* dsn = [NSString stringWithCString : dsName];
>> NSString* tmp = [@"-T:\"" stringByAppendingString:dsn];
>> tmp = [tmp stringByAppendingString:@"\","];
>> tmp = [tmp stringByAppendingString:ips];
>>
>> NSString* arg1 = [NSString stringWithFormat:@
>> "-T:\"%s\",%s",dsn,ips];
>>
>> arg1 = tmp;
>> NSLog(@"the command line is %@",arg1);
>> [args addObject:arg1];
>>
>> NSTask* theTask = [NSTask launchedTaskWithLaunchPath:excuPath
>> arguments:[NSArray arrayWithObjects:arg1,nil]];
>> [theTask waitUntilExit];
>>
>> when step "NSTask* theTask = [NSTask launchedTaskWithLaunchPath:excuPath
>> arguments:[NSArray arrayWithObjects:arg1,nil]]; " end, a thread will added
>> until main thread exit.
>>
>>
>> ---
>> Best Regards,
>> Xianyu
>>
>>
>>
>>
>>
>> On Dec 10, 2008, at 5:46 PM, Etienne Guérard wrote:
>>
>> Hi,
>>>
>>> On Dec 10, 2008, at 2:26 AM, Xianyu_Ge wrote:
>>>
>>> thanks for your reply. I means in my project, I want to use NSTask to
>>>> launch an application, and send application some parameters, when use NSTask
>>>> launch application that will add a new thread, right?
>>>>
>>>
>>> As far as I understand, you use NSTask to launch your application. But
>>> this does not imply that a new thread is created to monitor the launched
>>> process, unless of course, if you setup your own thread to monitor the
>>> process.
>>> So I think you assume that NSTask will use a thread but this is wrong.
>>> NSTask is just a wrapper around execve(), no threading involved here.
>>>
>>> and then send Apple event, when application received Apple event , it
>>>> will quit, usually, the thread starts by NSTask will exit, because the
>>>> application had quit, so I don't understand this, if use NSTask launch
>>>> application more times, thread count will always increased, even if
>>>> application had quit. I appreciate that any reply, thank you very much.
>>>>
>>>
>>> You can use ThreadViewer to convince yourself that there's no threading
>>> involved by using NSTask.
>>>
>>> EG
>>>
>>>
>>>> ---
>>>> Best Regards,
>>>> Xianyu
>>>>
>>>> On Dec 10, 2008, at 12:44 AM, Etienne Guérard wrote:
>>>>
>>>> I started an AP use NSTask in my project ,when I loaded this AP,
>>>>>> thread count will be increased ,after sending apple event to AP , and AP
>>>>>> will exit, but thread count can't decrease. If I used this method load AP
>>>>>> more times, thread count will increased, but there was no problem on tiger,
>>>>>> just present leopard. Sorry for my poor english.
>>>>>>
>>>>>
>>>>> I assume that "AP" acually means "application".
>>>>> I understand that you send some Apple event to your application like a
>>>>> "quit' event, right?
>>>>> You say that your application exit. OK. So what process the threads
>>>>> you're talking about belong to?
>>>>> Where does NSTask come into this?
>>>>>
>>>>> You have to be more precise to get an answer...
>>>>>
>>>>> EG
>>>>>
>>>>>
>>
> ------------------------------------------------------------
> This message and any attachments (the "message") are confidential and
> intended solely for the addressee(s). Any unauthorised use or dissemination
> is prohibited. E-mails are susceptible to alteration. Neither DxO Labs nor
> any of its subsidiaries or affiliates shall be liable for the message if
> altered, changed or falsified.
> Ce message et toutes les pieces jointes (ci-apres le "message") sont
> confidentiels et etablis a l'intention exclusive de ses destinataires. Toute
> utilisation ou diffusion non autorisee est interdite. Tout message
> electronique est susceptible d'alteration. DxO Labs et ses filiales
> declinent toute responsabilite au titre de ce message s'il a ete altere,
> modifie ou falsifie.
>
>
--
Best Regards
Xianyu
_______________________________________________
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