execl() question, help please..

In the documentation of the execl() function, it says that
“If you call this function from a process with more than one thread, all of
the threads are terminated and the new executable image is loaded and
executed. No destructor functions are called”.

My calling process is a multi-threaded process, and there will be
dynamically created arrays, pointers, fds and so forth that won’t be cleaned
up if the destructor does not get called.
My question is, what is the best procedure for running this execl()
function? without causing memory leaks, etc…

Any helps would be greatly appreciated.

inn.qnx.com <tburhan@dodo.com.au> wrote:

In the documentation of the execl() function, it says that
“If you call this function from a process with more than one thread, all of
the threads are terminated and the new executable image is loaded and
executed. No destructor functions are called”.

My calling process is a multi-threaded process, and there will be
dynamically created arrays, pointers, fds and so forth that won’t be cleaned
up if the destructor does not get called.
My question is, what is the best procedure for running this execl()
function? without causing memory leaks, etc…

All memory will be cleaned up automatically.

For the fds, set the close on exec flag after opening any fd, and they
will be automatically cleaned up.

But…why are you using execl() from a multi-threaded process? It seems
a strange thing to do, to me.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Thanks for you reply David,
execl() is just one of the options I looked at.
What I’m trying to achieve here is to replace the binary of the running
application with a new one.
So I thought by doing execl() to another binary / shell scripts that will
overwrite the old application
with the new one, I could achieve that.
What methods do you suggest?


“David Gibbs” <dagibbs@qnx.com> wrote in message
news:bq7sq8$l9e$1@nntp.qnx.com

inn.qnx.com <> tburhan@dodo.com.au> > wrote:
In the documentation of the execl() function, it says that
“If you call this function from a process with more than one thread, all
of
the threads are terminated and the new executable image is loaded and
executed. No destructor functions are called”.

My calling process is a multi-threaded process, and there will be
dynamically created arrays, pointers, fds and so forth that won’t be
cleaned
up if the destructor does not get called.
My question is, what is the best procedure for running this execl()
function? without causing memory leaks, etc…

All memory will be cleaned up automatically.

For the fds, set the close on exec flag after opening any fd, and they
will be automatically cleaned up.

But…why are you using execl() from a multi-threaded process? It seems
a strange thing to do, to me.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

inn.qnx.com <tburhan@dodo.com.au> wrote:

Thanks for you reply David,
execl() is just one of the options I looked at.
What I’m trying to achieve here is to replace the binary of the running
application with a new one.
So I thought by doing execl() to another binary / shell scripts that will
overwrite the old application
with the new one, I could achieve that.
What methods do you suggest?

The execl() will do that. It’s just that in a multi-threaded
application, there’s often multiple things going on (which is
why you have multiple threads) and the sudden decision by one
of the threads to completely remove the program and replace it
with another one is unusual.

Or, to put it another way, threads tend, most often, to be
used in servers. Ripping a running server out from under
clients is not, usually a good idea.

When you say you are looking to replace the running binary with a
new one, are you talking a new version of the same program, that is
an upgrade or bugfixed replacement?

For a case like that, I’d definitely look into making sure you’ve
gotten some sort of clean shutdown of services, especially of
any pending operations.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.