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: Fri, 17 Oct 2003 09:38:27 -0400
- Thread-topic: Memory Leak while using NSTask repeatedly
The preference panel is merely going to be a wrapper for some shell
scripts that would normally be run from the command line. It's a unix
product by design and we have a single start script that does a bunch of
stuff, starts each service using a binary service utility then checks to
make sure they started successfully using the service utility. A stop
script works in a similar fashion. The services are written in C/C++
and rely heavily on IPC so the order in which they start, and the timing
between starting them is crucial.
Any user can use a stat script which wraps around the ps command to
check the service status or a root user can use the service utility.
Because the service utility relies on the same IPC mutex files as the
services, it must be run as root along with the services. That means
the user has to authenticate before it can be used.
So the preference panel, in order to mimic the command-line tools above,
must be able to start the services (after authentication of course),
stop the services, and continuously check their status.
I am going to look into using the pid files but I have been watching the
process viewer and the loop really doesn't take much overhead. This is
a small detail and there are many larger issues that need to be
addressed so enhancing the services to communicate with the Preference
Panel is out of the question at this stage. If I were going to go
through the trouble of writing something to work with pid files (which
have plenty of holes anyway) I'd be better off writing some sort of
socket communication that the service could broadcast and the pref panel
could listen to.
Thanks, everyone, for your input. I have solved the memory leak with
NSAutoreleasePool. After running it overnight, the footprint stayed the
same size and it didn't crash (always a good thing).
~ Chris
-----Original Message-----
From: Chris Ridd [
mailto:email@hidden]
Sent: Friday, October 17, 2003 3:38 AM
To: Huyler, Christopher M
Cc: email@hidden
Subject: Re: Memory Leak while using NSTask repeatedly
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.