RE: Memory Leak while using NSTask repeatedly
RE: Memory Leak while using NSTask repeatedly
- Subject: RE: Memory Leak while using NSTask repeatedly
- From: "Huyler, Christopher M" <email@hidden>
- Date: Thu, 16 Oct 2003 17:15:55 -0400
- Thread-topic: Memory Leak while using NSTask repeatedly
Thank you. Sorry, I've only been working with Cocoa for a month or so
and I was unaware of the NSAutoreleasePool class and how it worked.
I actually don't know the pid of the processes but I will probably
enhance this loop once I get everything else working. For example, if
the user has authenticated, I can call one of our executables that will
send me more detailed information. But I don't want the user to
authenticate just to see if the process is up. I will add a check for
authentication that will decide what to use.
Another option is to use the ps command once to get the pid then use
kill like you suggested after that. However, this loop can get
complicated and unreliable because there are times (although not often)
that a service could stop or crash. Other services can detect this and
restart the service giving it a new pid. If I'm not doing a ps for the
service name, I won't know the service is up and running again. This
scenario can happen when starting all of our services at once because
they rely heavily on IPC. If one isn't ready another may shutdown.
Another process could also launch after my service exited which could be
given my processes' old pid. The user would think the process is
running when it isn't.
Additionally, I will have to execute a kill NSTask for each service (4
for a client, 5 for a server) whereas I can execute a single ps command
and get all the data I need. Which do you think is less cpu intensive?
Any other ways to check if a process is running?
Thanks for your input
~ Chris
-----Original Message-----
From: Chris Ridd [
mailto:email@hidden]
Sent: Thursday, October 16, 2003 2:26 PM
To: Huyler, Christopher M; email@hidden
Subject: Re: Memory Leak while using NSTask repeatedly
On 16/10/03 5:42 pm, Huyler, Christopher M <email@hidden>
wrote:
>
Is there some more clean-up that I am missing?
The autorelease pool is filling up with more and more copies of your
arguments, and you are not clearing the pool.
So there probably isn't a leak.
If you create a new pool at the start of the loop and release it at the
end
(by the sleep()) your memory usage should stablize.
BTW: polling for your process is "tacky", in that it uses unnecessary
CPU.
If there's another way to do it...
Also if you're just trying to test for the existence of a process which
you
know the pid for, try calling kill(pid, 0). That will succeed if the
process
is there, and fail if it isn't. That will be *much* cheaper than calling
ps
repeatedly :-)
Read 'man 2 kill' for the details.
Cheers,
Chris
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.