Hi,,
how to restart (self) application ?
I Need Clean all variable allocateds, and start again the program...
I Know this isn't the best method to a program, but i need urgent..
Printable View
Hi,,
how to restart (self) application ?
I Need Clean all variable allocateds, and start again the program...
I Know this isn't the best method to a program, but i need urgent..
Start a new instance of your program (and close the old one). Everything you've done up until then will be lost.
There is no other way, other than freeing the memory and resources you use (don't create memory and/or resource leaks!).
As I stated earilier (in the other thread - so I guess we should really stop that discussion there), this is non-trivial to do from within your application.
It is not too difficult to reset variables - just write a function that sets all global variables to known values. However, you will not be able to reset the heap, or any states stored inside library functions that you haven't got access to the global/static/heap-allocated variables of, and many other things that you can't "fix up" either.
You need to exit the application and start over again.
--
Mats
If you're on a UNIX environment, this isn't too difficult. Get back into the main() function somehow (either returning up to it, or longjmp'ing there), chdir() back to wherever you started (if you moved), close all open file descriptors except for stdin, stdout, stderr, then call:
This also assumes you haven't twiddled anything inside the argv array.Code:execv(argv[0], argv);
Yes, works very well [and we could use a setjmp/longjmp pair to get back to main, for example].
Unfortunately I happen to know that the OS that sergioms is using is not unix - it is a DOS-like OS for an embedded microcontroller, and it is sufficiently DOS-like to support Turbo C and Turbo C++, so I guess it performs an "exec()" more like a "spawn()" than Unix exec.
--
Mats
thanks a lot again
this topic maybe be closed, matsp helping me in other topic.