An overall function as a restart...

This is going to rasie a few eyebrows...

I have been thinking of running the WHOLE of the AudioScope project inside a function which I will call "restart()". A kind of wrapper function...

This is so that should there be anything that the user has set be wrong then a _cold_ start could be initialised again including deleting some Scope files if required...

I DO know that too many, (a lot of), recusions of this WILL cause a "segmenatation fault".

I was going to limit to say 5 restarts per session then any more and the program will stop.

The code like this:-

restart()
{
        ALL of the current and future scope code in here.
        Also restart can only be accessed from Command mode like...
        <pseudo_code>RESET calls restart()
}
restart

Alterntively if any of you know of any other way, like "GOTO" for example, then any input would be appreciated...
What are the opinions from you pro's.
I, as an amateur, would this sort of thing frowned upon?
Also, if, using this command a few times and then shutting down the program, AND, closing the terminal, can I guarantee the terminal closure will return all memory back to the pool?

I know I am asking some bizarre questions here but Google is not particularly my friend.
The Scope is now getting complex and making it _bullet_ proof is getting increasingly more difficult.

Thanks in advance...

If we assume that you have a shell script (AudioScope) and that you invoke it with a command line like:

AudioScope arg1 ... argn

and after running for a while it decides it needs to restart itself. One way to do that is to issue the command:

exec AudioScope "$@"

This will overlay the current shell script with a new invocation of the script without changing its process ID (i.e., $$ will not change). If the script has opened files and not closed them, they will remain open (so you'll need to close any files that aren't needed when you restart before calling exec). Exported variables will have the values they had before calling exec; local variables will disappear. If some of your options or operands have been processed and are not wanted in the restart, they can be shift'ed off before calling exec; but if you processed options using something like getopts and shifted them off, you'll need to be sure to add the needed options for the restart into the list of arguments given to the exec command. Note also that any buffered data in files that do remain open may be lost in by exec.

But, you can do this all day without overflowing your stack.

1 Like

Hi Don Cragun...

Many thanks, your knowledge, and that of a few others on here too, astounds me.

Where would I be without you guys... ;o)

I will try that out as RESET command.
(These things are logged down now, in my aging grey matter.)

Look out for it soon... ;oD