Re: Memory Leak while using NSTask repeatedly
Re: Memory Leak while using NSTask repeatedly
- Subject: Re: Memory Leak while using NSTask repeatedly
- From: Chris Ridd <email@hidden>
- Date: Fri, 17 Oct 2003 08:38:18 +0100
On 16/10/03 10:15 pm, Huyler, Christopher M <email@hidden>
wrote:
>
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.
That makes sense.
>
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.
It is a tradition to write daemon pids into files inside /var/run, so this
is one way to find what pid your daemon had. If the process dies but leaves
the pid file around, and the pid gets recycled by the OS, then you've got an
interesting problem. One solution I saw (here?) was to have the daemon
regularly update the timestamp on the pid file.
>
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?
If you've already got an NSTask object per service, then you should use
those to stop them. Otherwise it seems inefficient (to me) to create an
NSTask to kill each one. (Don't confuse the kill system call with the kill
shell command.)
If they're Cocoa processes then my understanding is that you *shouldn't*
just kill them, and instead you should send them Apple Events to quit.
I'm not sure this is terribly helpful, as I don't quite understand the
architecture of your application(s). It might make sense for you to recast
your question to one of the darwin lists.
>
Thanks for your input
>
>
~ Chris
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.