An overall function as a restart... | Unix Linux Forums | UNIX for Advanced & Expert Users

  Unix/Linux Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

An overall function as a restart...

UNIX for Advanced & Expert Users


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-13-2013
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 31 March 2015, 5:29 PM EDT
Location: Loughborough
Posts: 756
Thanks: 171
Thanked 171 Times in 138 Posts
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:-

Code:
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...
Sponsored Links
    #2  
Old Unix and Linux 07-13-2013
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 31 March 2015, 10:50 PM EDT
Location: San Jose, CA, USA
Posts: 5,957
Thanks: 242
Thanked 1,990 Times in 1,697 Posts
If we assume that you have a shell script (AudioScope) and that you invoke it with a command line like:

Code:
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:

Code:
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.
The Following User Says Thank You to Don Cragun For This Useful Post:
wisecracker (07-13-2013)
Sponsored Links
    #3  
Old Unix and Linux 07-13-2013
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 31 March 2015, 5:29 PM EDT
Location: Loughborough
Posts: 756
Thanks: 171
Thanked 171 Times in 138 Posts
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
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to step in one function after the function be executed in gdb? 915086731 Programming 4 10-31-2011 04:22 AM
SHELL SCRIPT Function Calling Another Function Please Help... omkar.sonawane Shell Programming and Scripting 2 04-13-2010 10:20 AM
Return a value from called function to the calling function mvictorvijayan Shell Programming and Scripting 1 09-14-2009 04:19 AM
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 11:39 AM
Postfix Restart kumarrana UNIX for Dummies Questions & Answers 4 02-16-2008 02:22 PM



All times are GMT -4. The time now is 11:10 PM.